Jacob Deichert


Reducing Rust Incremental Compilation Times on macOS by 70%

I may be late to the game, but I just read the Rust 1.51 release notes and noticed a new Cargo option that can help improve macOS compilation times. After upgrading and enabling the option, my incremental dev rebuilds went from ~14s to ~4s!

Speeding up builds with split-debuginfo

In the 1.51 release notes, there's a section about configuring how debug info is produced. It appears that by default on macOS, rustc runs a tool called dsymutil which analyzes the binary and then builds a directory of debug info next to it.

If you use cargo run for dev builds, you're likely building this debug info each time as it's the default for the dev profile.

But in 1.51, you can now configure split-debuginfo to skip the dsymutil process entirely! From the release notes:

Recently, Rust backtraces switched to using a different backend which supports loading debuginfo without needing to run dsymutil, and we've stabilized support for skipping the dsymutil run.

EDIT: Others have pointed out that this will soon become the default on macOS!

To configure this, open up your project's Cargo.toml and add this option:

[profile.dev]
split-debuginfo = "unpacked"
If you're using workspaces, you need to place this configuration in your root Cargo.toml, not within your individual crates.

If you've disabled the debug option then you likely will not see any speed boost since you're not generating debug info anyway. However, assuming you disabled debug because of slow compilation times in the past, you might be able to turn it on now and see if it's fast enough for you!

How much faster is it?

I'm currently working on a side project which has a backend API written in Rust. As I mentioned at the top of this post, my cargo run dev rebuilds went from around 14 seconds down to 4 seconds. Shaving off 70% of the build time is huge and hopefully means I'll be less likely to get distracted while it's recompiling 😅.

In terms of project size, I would consider the Rust API to be pretty small. But while it has a small surface area, it does pull in quite a few transitive dependencies which leads to longer build times. Dev rebuilds lasting 14 seconds was getting me a bit worried and I had missed the fact that I could have disabled the debug option to speed things up. But now with split-debuginfo enabled, 4 second rebuilds makes me pretty happy.

With that said, I'm not sure what the impact is for medium-large Rust projects... but give it a try and let me know!

Sidenote... this is my first Rust-related post in awhile! Follow my RSS feed if you're interested in future posts :)