You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by bl...@apache.org on 2026/03/20 19:50:46 UTC

(datafusion) branch db/cache-cores created (now c4c745e53e)

This is an automated email from the ASF dual-hosted git repository.

blaginin pushed a change to branch db/cache-cores
in repository https://gitbox.apache.org/repos/asf/datafusion.git


      at c4c745e53e cached `get_available_parallelism`

This branch includes the following new commits:

     new c4c745e53e cached `get_available_parallelism`

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org


(datafusion) 01/01: cached `get_available_parallelism`

Posted by bl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

blaginin pushed a commit to branch db/cache-cores
in repository https://gitbox.apache.org/repos/asf/datafusion.git

commit c4c745e53ebfac6d87f492bf005578b2a36fa696
Author: blaginin <gi...@blaginin.me>
AuthorDate: Fri Mar 20 19:50:33 2026 +0000

    cached `get_available_parallelism`
---
 datafusion/common/src/utils/mod.rs | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/datafusion/common/src/utils/mod.rs b/datafusion/common/src/utils/mod.rs
index 075a189c37..9752574002 100644
--- a/datafusion/common/src/utils/mod.rs
+++ b/datafusion/common/src/utils/mod.rs
@@ -40,7 +40,7 @@ use std::cmp::{Ordering, min};
 use std::collections::HashSet;
 use std::num::NonZero;
 use std::ops::Range;
-use std::sync::Arc;
+use std::sync::{Arc, LazyLock};
 use std::thread::available_parallelism;
 
 /// Applies an optional projection to a [`SchemaRef`], returning the
@@ -923,10 +923,15 @@ pub fn combine_limit(
 ///
 /// This is a wrapper around `std::thread::available_parallelism`, providing a default value
 /// of `1` if the system's parallelism cannot be determined.
+///
+/// The result is cached after the first call.
 pub fn get_available_parallelism() -> usize {
-    available_parallelism()
-        .unwrap_or(NonZero::new(1).expect("literal value `1` shouldn't be zero"))
-        .get()
+    static PARALLELISM: LazyLock<usize> = LazyLock::new(|| {
+        available_parallelism()
+            .unwrap_or(NonZero::new(1).expect("literal value `1` shouldn't be zero"))
+            .get()
+    });
+    *PARALLELISM
 }
 
 /// Converts a collection of function arguments into a fixed-size array of length N


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org