Skip to content

Commit f6281e8

Browse files
Change the default thread count to min(4, vCPUs)
This avoids the problems of high thread counts (i.e., contention in the kernel on the jobserver pipe due to thundering herd of readers) while stil giving rustc some parallelism to work with.
1 parent f0d4b57 commit f6281e8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/librustc_session/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,11 +1358,11 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13581358
"prints the LLVM optimization passes being run"),
13591359
ast_json: bool = (false, parse_bool, [UNTRACKED],
13601360
"print the AST as JSON and halt"),
1361-
// We default to 1 here since we want to behave like
1362-
// a sequential compiler for now. This'll likely be adjusted
1363-
// in the future. Note that -Zthreads=0 is the way to get
1364-
// the num_cpus behavior.
1365-
threads: usize = (1, parse_threads, [UNTRACKED],
1361+
// We default to min(4, vCPUs) here since we want to avoid spawning *too*
1362+
// many threads -- that causes scalability issues due to contention on
1363+
// the jobserver pipe (at least) -- but 4 is a reasonable amount on systems
1364+
// with lots of cores.
1365+
threads: usize = (std::cmp::min(::num_cpus::get(), 4), parse_threads, [UNTRACKED],
13661366
"use a thread pool with N threads"),
13671367
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
13681368
"print the pre-expansion AST as JSON and halt"),

0 commit comments

Comments
 (0)