Faster compilation with the parallel
编译过程
The compiler is split into two halves: the front-end and the back-end.
The front-end does many things, including:
- parsing / type checking / borrow checking.
- It uses Rayon to perform compilation tasks using fine-grained parallelism.
The back-end performs code generation:
- It generates code in chunks called "codegen units" and then LLVM processes these in parallel.
- This is a form of coarse-grained parallelism
Rust compilation has long benefited from interprocess parallelism, via Cargo, and from intraprocess parallelism in the back-end. It can now also benefit from intraprocess parallelism in the front-end
The compiler uses the jobserver protocol to limit the number of threads it creates.
How to use
# 安装最新 nightly 版本:rustc 1.75.0-nightly 以上
rustup default nightly
RUSTFLAGS="-Z threads=8" cargo build --release
或增加到配置文件:config.toml:
[build]
rustflags = ["-Z", "threads=8"]