Dynamic linking for compilation speed improvement?

The obvious problem here is that a significant chunk of compile times (majority?) is spend compiling generic code, and you can't dynamically link generics (short of JIT-compiling them on the fly, which would actually be fun).

TBH, at least in rust-analyzer's case, I haven't observed "linking is the bottleneck" effect. It seems that, even for incremental compiles, most of the time is spend compiling the chain of deps, and not in the final linking.

Is there some way I can instruct Cargo to do "everything but the final linking step", so that I can double-check linking times?

EDIT: for the curious, here's the compile time profile of rust-analyzer build, after adding a comment to one of the middle-end crates: https://gist.github.com/matklad/3fc87d13549b3810fe08dbb3e50228cc. 25 seconds in total, 7 seconds for the leaf binary crate, of which 5 seconds is linking.

EDIT: redoing the bench more carefully, it seems like the total time is more like 10s, which makes linking take 50% of that: Intuition for rustc current incremental compilation?

3 Likes