Live data from Hacker News

Cutting down Rust compile times from 30 to 2 minutes with one thousand crates

feldera.com

1–10 of 89 posts

Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates

#2
Eminently 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 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

#4
> We're using rustc v1.83, and despite having a 64-core machine with 128 threads, Rust barely puts any of them to work.

> 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

#5

Eminently 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…

They mention that compiling one crate at a time (-j1) doesnt give the 7x slowdown, which rules out the object file/caching-in-rustc theories... I think the only explanation is the rustcs are sharing limited L3 cache.

Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates

#8
> 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

#9
post #8

> 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?

Compilation is inherently pretty hard to parallelise, and various design decisions around how Rust modules/creates work make it even harder (as demonstrated by achieving greater parallelism here with many smaller crates). There's no particular reflection on the performance of rust code here, it's really a design/algorithms problem.

Re: Cutting down Rust compile times from 30 to 2 minutes with one thousand crates

#10
The main issue here is:

- 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).

Post reply on HN