HeadlinesBriefing HeadlinesBriefing.com

Emitting early metadata halves Rust build times

Hacker News •
×

Start dependent crates before their dependencies finish type-checking. Every crate waits for the crates it depends on to be fully checked, function bodies included, before it starts. It doesn't need those bodies to type-check itself. It compiles against the dependency's interface, the metadata in its .rmeta file. Headstart makes rustc write an early metadata file as soon as the interface is checked, and makes cargo start dependents on it.

Each crate's bodies are then checked while the crates downstream are already compiling. cargo check: dependents run to completion on early metadata. cargo build: dependents do all their analysis on early metadata, then wait for the dependency's full metadata before generating code. While they wait, they give their job slot back. If a body has an error, the build still fails with that error, with the same diagnostics and exit status as today.

On rustc's default front end, headstart makes clean builds of 13 real projects (rust-analyzer, zed, bevy, lemmy, polars and others) up to 54% faster for cargo check, and up to 42% for cargo build. None is slower. With the parallel front end (-Zthreads=8), which covers some of the same ground, it adds up to 25%. Those are 16-core numbers. The gain comes from cores the build would leave idle, so it shrinks on smaller machines. On 4 cores, rust-analyzer's check is 24% faster and its build 13–15%.

Source: Hacker News · Summarized by HeadlinesBriefing