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.
This commit is contained in:
Samuel Tardieu 2023-03-02 13:21:35 +01:00
parent 113c704d22
commit 446ae429a6

View File

@ -89,14 +89,11 @@ pub fn new() -> Self {
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::<usize>("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