Skip to content

Commit fa0a728

Browse files
back: Limit the number of LLVM worker threads.
1 parent a3da24b commit fa0a728

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: src/librustc_trans/back/write.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use errors::emitter::Emitter;
2727
use syntax_pos::MultiSpan;
2828
use context::{is_pie_binary, get_reloc_model};
2929

30+
use std::cmp;
3031
use std::ffi::CString;
3132
use std::fs;
3233
use std::path::{Path, PathBuf};
@@ -754,10 +755,13 @@ pub fn run_passes(sess: &Session,
754755
}
755756

756757
// Process the work items, optionally using worker threads.
757-
// NOTE: This code is not really adapted to incremental compilation where
758-
// the compiler decides the number of codegen units (and will
759-
// potentially create hundreds of them).
760-
let num_workers = work_items.len() - 1;
758+
// NOTE: We are hardcoding a limit of worker threads for now. With
759+
// incremental compilation we can run into situations where we would
760+
// open hundreds of threads otherwise -- which can make things slower
761+
// if things don't fit into memory anymore, or can cause the compiler
762+
// to crash because of too many open file handles. See #39280 for
763+
// some discussion on how to improve this in the future.
764+
let num_workers = cmp::min(work_items.len() - 1, 32);
761765
if num_workers <= 1 {
762766
run_work_singlethreaded(sess, &trans.exported_symbols, work_items);
763767
} else {

0 commit comments

Comments
 (0)