Rust: Fast BuildsFri, Dec 16, 2022
This year I started programming in Rust, and while the language is an amazing innovation in so many ways, it has felt like 10 steps backwards in developer experience. Specifically in terms of build times. Once again xkcd rang true.
After trying lots of different things people suggested for speeding up builds I’ve found the following two things are what make the biggest difference for my projects.
1. Buy a fast machine
When I compare the performance of an older Apple Intel with a newer Apple Silicon M1MAX, the difference is stark. It’s difficult to put a price on how much time I’ve saved just waiting for code to build, or time I’ve saved by not losing flow state from waiting.
sccache to cache build artifacts
It’s as easy as:
cargo install sccache
brew install sccache
Then place the following in your shell files:
export RUSTC_WRAPPER="$(which sccache)"
The next times you build, build artifacts will be cached in a single global cache, which means caching across projects.
There are some other things I’ve seen others recommend, like using RAM disk, or
alternative linkers like
zld. I’ve tried them, and I found no or minimal
benefit in them on the projects I work on with the hardware I have. If you don’t
have a fast SSD then a RAM disk might be an improvement. You might want to
explore them, they just haven’t yielded a benefit for me.