From 446ae429a6e30b416853d6ae0dea228b751671b0 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 2 Mar 2023 13:21:35 +0100 Subject: [PATCH] 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. --- lintcheck/src/config.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lintcheck/src/config.rs b/lintcheck/src/config.rs index e0244ddcecb..f87b902b92d 100644 --- a/lintcheck/src/config.rs +++ b/lintcheck/src/config.rs @@ -89,14 +89,11 @@ impl LintcheckConfig { if markdown { "md" } else { "txt" } )); - // look at the --threads arg, if 0 is passed, ask rayon rayon how many threads it would spawn and - // use half of that for the physical core count - // by default use a single thread + // look at the --threads arg, if 0 is passed, use the threads count let max_jobs = match clap_config.get_one::("threads") { Some(&0) => { // automatic choice - // Rayon seems to return thread count so half that for core count - rayon::current_num_threads() / 2 + std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1) }, Some(&threads) => threads, // no -j passed, use a single thread