Skip to content

Commit ed1fa3f

Browse files
committed
Use a single codegen unit for fully optimized builds.
1 parent 8b4b208 commit ed1fa3f

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Diff for: config.example.toml

+6-5
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ changelog-seen = 2
429429
# Set this to `true` to download unconditionally (useful if e.g. you are only changing doc-comments).
430430
#download-rustc = false
431431

432-
# Number of codegen units to use for each compiler invocation. A value of 0
433-
# means "the number of cores on this machine", and 1+ is passed through to the
434-
# compiler.
432+
# Number of codegen units to use for each compiler invocation. If specified: a
433+
# value of 0 means "the number of cores on this machine", and 1+ is passed
434+
# through to the compiler.
435435
#
436-
# Uses the rustc defaults: https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units
437-
#codegen-units = if incremental { 256 } else { 16 }
436+
# The default value depends on various things, and is also described here:
437+
# https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units
438+
#codegen-units = if optimize && !debug && !incremental { 1 } else if incremental { 256 } else { 16 }
438439

439440
# Sets the number of codegen units to build the standard library with,
440441
# regardless of what the codegen-unit setting for the rest of the compiler is.

Diff for: src/bootstrap/config.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ impl Config {
10951095
let mut llvm_assertions = None;
10961096
let mut llvm_tests = None;
10971097
let mut llvm_plugins = None;
1098+
let mut rust_codegen_units = None;
1099+
let mut rust_codegen_units_std = None;
10981100
let mut debug = None;
10991101
let mut debug_assertions = None;
11001102
let mut debug_assertions_std = None;
@@ -1173,8 +1175,8 @@ impl Config {
11731175
backends.iter().map(|s| INTERNER.intern_str(s)).collect();
11741176
}
11751177

1176-
config.rust_codegen_units = rust.codegen_units.map(threads_from_config);
1177-
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
1178+
rust_codegen_units = rust.codegen_units.map(threads_from_config);
1179+
rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
11781180
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
11791181
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
11801182
config.download_rustc_commit = config.download_ci_rustc_commit(rust.download_rustc);
@@ -1368,6 +1370,16 @@ impl Config {
13681370
config.llvm_plugins = llvm_plugins.unwrap_or(false);
13691371
config.rust_optimize = optimize.unwrap_or(true);
13701372

1373+
let fully_optimized = config.rust_optimize && debug != Some(true) && !config.incremental;
1374+
if fully_optimized && rust_codegen_units.is_none() {
1375+
rust_codegen_units = Some(1)
1376+
}
1377+
if fully_optimized && rust_codegen_units_std.is_none() {
1378+
rust_codegen_units_std = Some(1)
1379+
}
1380+
config.rust_codegen_units = rust_codegen_units;
1381+
config.rust_codegen_units_std = rust_codegen_units_std;
1382+
13711383
let default = debug == Some(true);
13721384
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
13731385
config.rust_debug_assertions_std =

Diff for: src/doc/rustc/src/codegen-options/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Supported values can also be discovered by running `rustc --print code-models`.
3131

3232
## codegen-units
3333

34+
njn: wrong about 0
3435
This flag controls how many code generation units the crate is split into. It
3536
takes an integer greater than 0.
3637

@@ -39,6 +40,7 @@ them in parallel. Increasing parallelism may speed up compile times, but may
3940
also produce slower code. Setting this to 1 may improve the performance of
4041
generated code, but may be slower to compile.
4142

43+
njn: update
4244
The default value, if not specified, is 16 for non-incremental builds. For
4345
incremental builds the default is 256 which allows caching to be more granular.
4446

0 commit comments

Comments
 (0)