Speculative Compilation for Faster Compiles

An oversimplified way of looking at why compile times are so long in rust is because of module dependencies.

C depends on B which depends on A.

If B and C assume they know the info they need, possibly from a prior compilation, they can be speculatively compiled with that information simultaneously.

If that assumption proves to be in error, compilation restarts.

The is shared in the spirit of brainstorming, and hopes that it sparks more ideas given the real-world complexity.

Crates are currently compiled this way? Or maybe you are describing something like a checkpoint scheme where you revert to a previously valid compilation state as long as you can. What is really needed is a way to only recompile the parts of A, B, or C which changed since the last compile. Currently, as far as I'm currently aware, that isn't possible.

rustc has[1] support for incremental compilation, which aims to do just that.

  1. cargo too ↩︎

A monumental accomplishment!

Major kudos to everything you guys have accomplished... and this is just some seat of the pants brainstorming... Thanks for the consideration.

From afar, it seems like there should be a way to reuse more bits of the compilation work products when recompiling.

A corollary idea involves caching pieces of the work product, possibly in a shared repository. For example, find the largest branches of the Abstract Syntax Tree that match a crc, and return those results instead of recompiling.

In some ways, this would make most every compilation into an incremental compilation, especially if people share a world wide cache repo.

Here's a bunch of old-ish ideas to speed up the compiler, which progressed at various rates (e.g. thinLTO is availabe on stable, query parallelization is available on nightly, whereas MIR-only RLIBs afaik never went past the initial prototyping stage).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.