Emitting metadata early makes building/checking Rust up to twice as fast

138 points · 36 comments on HN · read original →

Points and comments are a snapshot, not live.

Eager metadata emission speeds up Rust builds by up to 54% for cargo check.

Headstart makes rustc write an early metadata file once a crate's interface is checked, letting dependents start before function bodies finish. In clean builds of 13 real projects, cargo check is up to 54% faster and cargo build up to 42% faster on 16 cores. The gain comes from using otherwise idle cores. The patches split analysis into item interfaces and function bodies, and cargo tracks early metadata to start dependents early. If a body has an error, downstream work is discarded, but diagnostics and exit status remain the same.

What commenters are saying

Commenters are broadly excited about the performance gains, noting the approach resembles optimistic branch prediction or deeper pipelining of build units. Some point out that Rust already had pipelined builds since 2019, and that this extends it by making metadata emission even earlier. There is discussion about edge cases like `-> impl Trait` that expose concrete types from bodies; the author notes these functions are type-checked early anyway. The thread also notes the patches are LLM-generated, which the Rust project typically rejects for mainline, but the idea itself is valued for demonstrating feasibility.