-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use -Z threads=0
option in config_fast_builds.toml
#11541
Use -Z threads=0
option in config_fast_builds.toml
#11541
Conversation
.cargo/config_fast_builds.toml
Outdated
@@ -16,6 +17,7 @@ rustflags = [ | |||
rustflags = [ | |||
"-Clink-arg=-fuse-ld=/usr/local/opt/llvm/bin/ld64.lld", # Use LLD Linker | |||
"-Zshare-generics=y", # (Nightly) Make the current crate share its generic instantiations | |||
"-Zthreads=8", # (Nightly) Use improved multithreading with 8 threads. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can any MacOS users test if this works well? It might reduce performance on MacOS or even not work at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After testing it on my M1 Mac, this option actually seems to slow down the compilation process. I built with the --timings
option to generate the following charts. The time increases from 58.4 seconds to 63.6 seconds.
Before:
After:
Edit: Redid timings so the only difference between "Before" and "After" was commenting out -Zthreads=0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an average or just one test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was just one test. Here's my results running cargo clean && cargo +nightly build
with and without -Zthreads=0
commented out.
Before
- 1:03s
- 1:06s
- 1:11s
- 1:12s
- 1:08s
- 0:59.4s
- 1:03s
Average: 1:06.05s
After
- 1:05s
- 1:11s
- 1:13s
- 1:20s
- 1:07s
- 1:11s
- 1:12s
Average: 1:11.29s
.cargo/config_fast_builds.toml
Outdated
linker = "rust-lld.exe" # Use LLD Linker | ||
rustflags = [ | ||
"-Zshare-generics=n", | ||
"-Zthreads=8", # (Nightly) Use improved multithreading with 8 threads. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows users should also test this out
I suggest to:
With this we can compile instantly, I guess .... But seriously talking, why 8 ? Is there any way to automatically set it to max (best) number possible for given CPU? |
That's the recommended amount.
After reading some rustc source code, I realised that |
-Z threads=8
option in config_fast_builds.toml
-Z threads=0
option in config_fast_builds.toml
) # Objective Improve compile times. ## Solution The `-Z threads=0` option has been introduced into nightly rust somewhat recently, and was showcased in this [rust-lang article](https://blog.rust-lang.org/2023/11/09/parallel-rustc.html). This option improves multithreading in rust and speeds up compilation. I added this option to `config_fast_builds.toml` so others can also use this option to improve compile times. `-Z threads=0` automatically uses the same amount of threads as the amount of threads in your system (See [rustc source code](https://github.com/rust-lang/rust/blob/6b4f1c5e782c72a047a23e922decd33e7d462345/compiler/rustc_session/src/options.rs#L617)). ### Benchmarks > **Disclaimer:** This section was written before I knew of `-Z threads=0`, so it uses `-Z threads=8` instead. I compiled bevy with/without the `-Z threads=8` and saw about a 7% improvement in compliation times on my Kubuntu system with a 13th Gen Intel® Core™ i5-13400. Also the compile times go down over time, probably because I had other things running in the background. #### Without `-Z threads=8` - 42.33s - 40.90s - 38.27s - 38.07s - 37.17s - 37.67s - 36.63s - 37.24s **Average**: 38.535 #### With `-Z threads=8` - 36.77s - 39.50s - 38.86s - 35.61s - 34.37s - 34.32s - 34.44s - 33.74s **Average**: 35.95125
Objective
Improve compile times.
Solution
The
-Z threads=0
option has been introduced into nightly rust somewhat recently, and was showcased in this rust-lang article. This option improves multithreading in rust and speeds up compilation. I added this option toconfig_fast_builds.toml
so others can also use this option to improve compile times.-Z threads=0
automatically uses the same amount of threads as the amount of threads in your system (See rustc source code).Benchmarks
I compiled bevy with/without the
-Z threads=8
and saw about a 7% improvement in compliation times on my Kubuntu system with a 13th Gen Intel® Core™ i5-13400.Also the compile times go down over time, probably because I had other things running in the background.
Without
-Z threads=8
Average: 38.535
With
-Z threads=8
Average: 35.95125