Skip to content

Commit 446ae42

Browse files
committed
lintcheck: fix parallel processing handling
Using `rayon::current_num_threads()` causes a bug: ``` thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ThreadPoolBuildError { kind: GlobalPoolAlreadyInitialized }', src/main.rs:632:10 ``` Moreover, using the number of threads and dividing it by 2 wouldn't return the number of physical threads on modern processors which have a varying number of threads per core. It makes little sense to restrict ourselves to physical threads, especially when, in modern architectures, cores with multiple threads are often faster (performance) while cores with a unique threads are often slower (efficient). The Rust runtime will make a better choice.
1 parent 113c704 commit 446ae42

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

lintcheck/src/config.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,11 @@ impl LintcheckConfig {
8989
if markdown { "md" } else { "txt" }
9090
));
9191

92-
// look at the --threads arg, if 0 is passed, ask rayon rayon how many threads it would spawn and
93-
// use half of that for the physical core count
94-
// by default use a single thread
92+
// look at the --threads arg, if 0 is passed, use the threads count
9593
let max_jobs = match clap_config.get_one::<usize>("threads") {
9694
Some(&0) => {
9795
// automatic choice
98-
// Rayon seems to return thread count so half that for core count
99-
rayon::current_num_threads() / 2
96+
std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1)
10097
},
10198
Some(&threads) => threads,
10299
// no -j passed, use a single thread

0 commit comments

Comments
 (0)