Skip to content

Commit 5818dcd

Browse files
authored
Add parallel frontend to the build performance guide (#15970)
This extends the build performance guide in the Cargo book with the parallel frontend. This is the first mechanism we have in the guide that is not configured via profiles (unless we want to advertise setting `rustflags` through profiles?), but rather through `RUSTFLAGS`. Which means that we have to explain how to do that. I proposed using footnotes for this, so that we can reuse them also for other thing (such as explaining how to change a profile). An alternative would be to have a short paragraph at the beginning of the configuration subsection where we explain all the possible ways of configuring things, and then we refer to them. This is a follow up to #15924 r? @epage
2 parents afb508e + a887a25 commit 5818dcd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/doc/src/guide/build-performance.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,29 @@ This will change the [`dev` profile](../reference/profiles.md#dev) to use the [C
6363

6464
Trade-offs:
6565
- ✅ Faster code generation (`cargo build`)
66-
- ❌ **Requires using nightly Rust and an unstable Cargo feature**
66+
- ❌ **Requires using nightly Rust and an [unstable Cargo feature][codegen-backend-feature]**
6767
- ❌ Worse runtime performance of the generated code
6868
- Speeds up build part of `cargo test`, but might increase its test execution part
6969
- ❌ Only available for [certain targets](https://github.com/rust-lang/rustc_codegen_cranelift?tab=readme-ov-file#platform-support)
7070
- ❌ Might not support all Rust features (e.g. unwinding)
71+
72+
[codegen-backend-feature]: ../reference/unstable.md#codegen-backend
73+
74+
### Enable the experimental parallel frontend
75+
76+
Recommendation: Add to your `.cargo/config.toml`:
77+
78+
```toml
79+
[build]
80+
rustflags = "-Zthreads=8"
81+
```
82+
83+
This [`rustflags`][build.rustflags] will enable the [parallel frontend][parallel-frontend-blog] of the Rust compiler, and tell it to use `n` threads. The value of `n` should be chosen according to the number of cores available on your system, although there are diminishing returns. We recommend using at most `8` threads.
84+
85+
Trade-offs:
86+
- ✅ Faster build times
87+
-**Requires using nightly Rust and an [unstable Rust feature][parallel-frontend-issue]**
88+
89+
[parallel-frontend-blog]: https://blog.rust-lang.org/2023/11/09/parallel-rustc/
90+
[parallel-frontend-issue]: https://github.com/rust-lang/rust/issues/113349
91+
[build.rustflags]: ../reference/config.md#buildrustflags

0 commit comments

Comments
 (0)