Skip to content

Commit bef2ace

Browse files
committed
refactor(tasks): always explicitly initialize Rayon thread pool (#13123)
Similar to #13122. Unconditionally initialize Rayon global thread pool in coverage runner. The guarantees provided by explicitly initializing the thread pool are going to be critical for the linter. Coverage currently doesn't cover linter, so it doesn't matter, but this doesn't hurt to do, and gives us greater safety if coverage does involve the linter at a later date.
1 parent 6c5b8be commit bef2ace

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tasks/coverage/src/main.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use oxc_coverage::AppArgs;
1+
use std::num::NonZeroUsize;
2+
23
use pico_args::Arguments;
34
use rayon::ThreadPoolBuilder;
45

6+
use oxc_coverage::AppArgs;
7+
58
fn main() {
69
let mut args = Arguments::from_env();
710
let command = args.subcommand().expect("subcommands");
@@ -13,9 +16,13 @@ fn main() {
1316
diff: args.contains("--diff"),
1417
};
1518

16-
if args.debug {
17-
ThreadPoolBuilder::new().num_threads(1).build_global().unwrap();
18-
}
19+
// Init rayon thread pool
20+
let thread_count = if args.debug {
21+
1
22+
} else {
23+
std::thread::available_parallelism().map(NonZeroUsize::get).unwrap_or(1)
24+
};
25+
ThreadPoolBuilder::new().num_threads(thread_count).build_global().unwrap();
1926

2027
let task = command.as_deref().unwrap_or("default");
2128
match task {

0 commit comments

Comments
 (0)