Skip to content

Commit 6dc948e

Browse files
committed
limit rustfmt parallelism by taking -j into account
1 parent 211d49c commit 6dc948e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/bootstrap/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ pub fn format(build: &Build, check: bool) {
122122
WalkBuilder::new(src.clone()).types(matcher).overrides(ignore_fmt).build_parallel();
123123

124124
// there is a lot of blocking involved in spawning a child process and reading files to format.
125-
// spawn more processes than available cores to keep the CPU busy
126-
let max_processes = num_cpus::get() * 2;
125+
// spawn more processes than available concurrency to keep the CPU busy
126+
let max_processes = build.jobs() as usize * 2;
127127

128128
// spawn child processes on a separate thread so we can batch entries we have received from ignore
129129
let thread = std::thread::spawn(move || {
@@ -135,7 +135,7 @@ pub fn format(build: &Build, check: bool) {
135135
let child = rustfmt(&src, &rustfmt_path, paths.as_slice(), check);
136136
children.push_back(child);
137137

138-
if children.len() > max_processes {
138+
if children.len() >= max_processes {
139139
// await oldest child
140140
children.pop_front().unwrap()();
141141
}

0 commit comments

Comments
 (0)