From c419845cfeb1c7ab9ca959de66e90b9dacbc25b7 Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Mon, 13 Jun 2022 14:16:58 -0500 Subject: [PATCH] Take `.max(1)` when computing MAX_RAYON_THREADS (#25940) --- rayon-threadlimit/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rayon-threadlimit/src/lib.rs b/rayon-threadlimit/src/lib.rs index 81086d0bf1..6d006de86e 100644 --- a/rayon-threadlimit/src/lib.rs +++ b/rayon-threadlimit/src/lib.rs @@ -8,9 +8,10 @@ lazy_static! { // reduce the number of threads each pool is allowed to half the cpu core count, to avoid rayon // hogging cpu static ref MAX_RAYON_THREADS: usize = - env::var("SOLANA_RAYON_THREADS") - .map(|x| x.parse().unwrap_or(num_cpus::get() as usize / 2)) - .unwrap_or(num_cpus::get() as usize / 2); + env::var("SOLANA_RAYON_THREADS").ok() + .and_then(|num_threads| num_threads.parse().ok()) + .unwrap_or_else(|| num_cpus::get() as usize / 2) + .max(1); } pub fn get_thread_count() -> usize {