equal
deleted
inserted
replaced
496 iter.filter_map(move |result| match result { |
496 iter.filter_map(move |result| match result { |
497 Ok(node) => f(node).transpose(), |
497 Ok(node) => f(node).transpose(), |
498 Err(e) => Some(Err(e)), |
498 Err(e) => Some(Err(e)), |
499 }) |
499 }) |
500 } |
500 } |
|
501 |
|
502 /// Force the global rayon threadpool to not exceed 16 concurrent threads |
|
503 /// unless the user has specified a value. |
|
504 /// This is a stop-gap measure until we figure out why using more than 16 |
|
505 /// threads makes `status` slower for each additional thread. |
|
506 /// |
|
507 /// TODO find the underlying cause and fix it, then remove this. |
|
508 /// |
|
509 /// # Errors |
|
510 /// |
|
511 /// Returns an error if the global threadpool has already been initialized if |
|
512 /// we try to initialize it. |
|
513 pub fn cap_default_rayon_threads() -> Result<(), rayon::ThreadPoolBuildError> { |
|
514 const THREAD_CAP: usize = 16; |
|
515 |
|
516 if std::env::var("RAYON_NUM_THREADS").is_err() { |
|
517 let available_parallelism = std::thread::available_parallelism() |
|
518 .map(usize::from) |
|
519 .unwrap_or(1); |
|
520 let new_thread_count = THREAD_CAP.min(available_parallelism); |
|
521 let res = rayon::ThreadPoolBuilder::new() |
|
522 .num_threads(new_thread_count) |
|
523 .build_global(); |
|
524 if res.is_ok() { |
|
525 log::trace!( |
|
526 "Capped the rayon threadpool to {new_thread_count} threads", |
|
527 ); |
|
528 } |
|
529 return res; |
|
530 } |
|
531 Ok(()) |
|
532 } |