Skip to content
GitHub·

🚀Rust Headstart Speeds Up Cargo Builds by Up to 54%

Cargo builds get a major speed boost with Headstart

TL;DR

Rust's Headstart feature speeds up cargo builds by up to 54% by starting dependent crates before their dependencies finish type-checking. This is a big win for developers working on large Rust projects.

Rust's Headstart feature speeds up cargo builds by up to 54% by starting dependent crates before their dependencies finish type-checking. This is a big win for developers working on large Rust projects, as it reduces the time spent waiting for dependencies to finish before the dependent crates can start. Headstart works by compiling against the dependency's interface using the metadata in its .rmeta file, allowing dependents to run to completion on early metadata. However, it also comes with costs like work downstream that gets thrown away and more memory in use at once. The gain from Headstart shrinks on smaller machines, but on 4 cores, rust-analyzer's check is 24% faster and its build 13-15%, and codex-rs's check is 14%.

Rust Headstart Speeds Up Cargo Builds by Up to 54% — GitHub

Key Points

1

Headstart makes rustc write an early metadata file as soon as the interface is checked, allowing dependents to start compiling early.

2

In cargo check, dependents run to completion on early metadata, reducing build times by up to 54% for 13 real projects.

3

In cargo build, dependents do all their analysis on early metadata, then wait for the dependency's full metadata before generating code.

4

Headstart includes a new analysis_interfaces query that splits analysis into item interfaces and function bodies, improving efficiency.

5

Headstart includes a test suite with 53 rustc-perf compile benchmarks to ensure performance gains are consistent.

Why It Matters

If you're working on a large Rust project, Headstart can make your life much easier. For example, rust-analyzer's check is 24% faster and its build 13-15% faster on 4 cores. This means less waiting around and more coding time. However, the gains shrink on smaller machines, so it's not a silver bullet for everyone.

rustcargobuild-speedheadstartrustc

Comments

Subscribe to join the conversation...

Be the first to comment

Enjoyed this article?

Get it daily. 7am. Free. Reads in 5 minutes.

Also get