Skip to content

Commit 73aae5d

Browse files
committed
Use num_cpus-1 threads by default
1 parent 4f404e9 commit 73aae5d

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

extractor/src/main.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,24 @@ impl TrapCompression {
5454
* "If the number is positive, it indicates the number of threads that should
5555
* be used. If the number is negative or zero, it should be added to the number
5656
* of cores available on the machine to determine how many threads to use
57-
* (minimum of 1). If unspecified, should be considered as set to 1."
57+
* (minimum of 1). If unspecified, should be considered as set to -1."
5858
*/
5959
fn num_codeql_threads() -> usize {
60-
match std::env::var("CODEQL_THREADS") {
61-
// Use 1 thread if the environment variable isn't set.
62-
Err(_) => 1,
63-
64-
Ok(num) => match num.parse::<i32>() {
65-
Ok(num) if num <= 0 => {
66-
let reduction = -num as usize;
67-
num_cpus::get() - reduction
68-
}
69-
Ok(num) => num as usize,
70-
71-
Err(_) => {
72-
tracing::error!(
73-
"Unable to parse CODEQL_THREADS value '{}'; defaulting to 1 thread.",
74-
&num
75-
);
76-
1
77-
}
78-
},
60+
let threads_str = std::env::var("CODEQL_THREADS").unwrap_or("-1".to_owned());
61+
match threads_str.parse::<i32>() {
62+
Ok(num) if num <= 0 => {
63+
let reduction = -num as usize;
64+
std::cmp::max(1, num_cpus::get() - reduction)
65+
}
66+
Ok(num) => num as usize,
67+
68+
Err(_) => {
69+
tracing::error!(
70+
"Unable to parse CODEQL_THREADS value '{}'; defaulting to 1 thread.",
71+
&threads_str
72+
);
73+
1
74+
}
7975
}
8076
}
8177

0 commit comments

Comments
 (0)