~3x compilation speedup, is any movement into this direction?

My program too slow if I use debug compilation mode, so I am always compile in release mode, recently I re-evaluate compile time of my main crate in workspace (rust 1.34.2):

touch src/lib.rs && cargo build --release ~ 9.7 seconds
touch build.rs && cargo build --release ~ 14.7 seconds

but if I add:

incremental = true
codegen-units = 16

to [profile.release]:

touch src/lib.rs && cargo build --release ~3.4 seconds
touch build.rs && cargo build --release ~5.7 seconds

huge compile time boost, but for some reason this is not default, any current work into enabling these options by default?

3.4 seconds is something that make everyday work is possible, while ~10 seconds for compile/run cycle is too huge.

Codegen units has an impact on quality of generated code (mainly inlining), and therefore is not enabled by default on release.

I recommend that you set opt-level = 1 (or whatever level fits you) for profile.debug.


Ok, I try without codgen-units=16, only with incremental = true, build time changes is neglectable, 3.6 secs vs 3.4 secs.

So it is incremental feature gives such huge speedup. As I rembemer it was introduced long time ago, but still not true for release build, is it also produces not optimal code?


Yes, incremental compilation also affects code generation quality.

There is a tracking issue for making incremental the default: https://github.com/rust-lang/rust/issues/57968

Some benchmarking was done earlier this year, and it looked promising. The issue has more details.

Yes I saw it and after that actually I posted on this forum. Because of bottom of issue discussion is related to cargo custom profiles and Windows + anti-viruses. So looks like this is highly promissing feature development is stopped.

1 Like

I haven’t read the tracking issue, but would it be possible to instead add a third mode that has most of the optimizations in release, but also has incremental and other things that have a similar performance vs compile time tradeoffs.

Sorry if this was already discussed.

There is dissussion about this in the last comments: https://github.com/rust-lang/rust/issues/57968 17

There is cargo named profiles: https://github.com/rust-lang/cargo/issues/6988 you can define any profiles that you want, for example you can introduce dev profile that incremetal + release,

but this doesn’t improve things if incremental have some pitfals.

codegen-units has no effect in incremental mode. In incremental mode a single codegen unit will be created for every module: