Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
1–10 of 89 posts
Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#2It’s not surprising they didn’t see a linear speedup from splitting into so many crates. The compiler now produces a large number of intermediate object files that must be read back and linked into the final binary. On top of that, rustc caches a significant amount of semantic information — lifetimes, trait resolutions, type inference — much of which now has to be recomputed for each crate, including dependencies. That introduces a lot of redundant work.
I also would expect this to hurt runtime performance as it likely reduces inlining opportunities (unless LTO is really good now?)
Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#3Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#4> That’s right — 1,106 crates! Sounds excessive? Maybe. But in the end this is what makes rustc much more effective.
> What used to take 30–45 minutes now compiles in under 3 minutes.
I wonder if this kind of trick can be implemented in rustc itself in a more automated fashion to benefit more projects.
Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#5Eminently pragmatic solution — I like it. In Rust, a crate is a compilation unit, and the compiler has limited parallelism opportunities, especially since rustc offloads much of the work to LLVM, which is largely single-threaded. It’s not surprising they didn’t see a linear speedup from splitting into so many crates. The compiler now produces a large number of intermediate object files that must be read back and link…
Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#6Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#7Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#8Rust is fast in theory, but if in practice they can't even get their compiler to squeeze any juice from the CPU, then what's the value of that language from a software engineering viewpoint?
Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#9> despite having a 64-core machine with 128 threads, Rust barely puts any of them to work. Rust is fast in theory, but if in practice they can't even get their compiler to squeeze any juice from the CPU, then what's the value of that language from a software engineering viewpoint?
Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates
#10- in rust one semantic compilation unit is one crate
- in C one semantic compilation unit is one file
There are quite a bunch of benefits in the rust approach, but also drawbacks, like huge projects have to be split into multiple workspaces to maximize parallel building.
Oversimplified the codegen-units setting tells the compiler into how many parts the compiler is allowed to split the a single semantic code gen unit.
Now it still seems strange (as in it looks like a performance bug) that most times rust was stuck in just one threat (instead of e.g. 8).