From 13ff0e9f2aad16682fe188bd8d7c60e6d80a2cf2 Mon Sep 17 00:00:00 2001 From: nameexhaustion Date: Mon, 12 Aug 2024 21:37:47 +1000 Subject: [PATCH] perf: Reduce default async thread count (#18142) --- crates/polars-io/src/pl_async.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/polars-io/src/pl_async.rs b/crates/polars-io/src/pl_async.rs index b9731751483d..cc43a908cda3 100644 --- a/crates/polars-io/src/pl_async.rs +++ b/crates/polars-io/src/pl_async.rs @@ -237,8 +237,16 @@ pub struct RuntimeManager { impl RuntimeManager { fn new() -> Self { + let n_threads = std::env::var("POLARS_ASYNC_THREAD_COUNT") + .map(|x| x.parse::().expect("integer")) + .unwrap_or((POOL.current_num_threads() / 4).clamp(1, 4)); + + if polars_core::config::verbose() { + eprintln!("Async thread count: {}", n_threads); + } + let rt = Builder::new_multi_thread() - .worker_threads(std::cmp::max(POOL.current_num_threads(), 4)) + .worker_threads(n_threads) .enable_io() .enable_time() .build()