File tree Expand file tree Collapse file tree
datafusion/common/src/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ use std::cmp::{Ordering, min};
4040use std:: collections:: HashSet ;
4141use std:: num:: NonZero ;
4242use std:: ops:: Range ;
43- use std:: sync:: Arc ;
43+ use std:: sync:: { Arc , LazyLock } ;
4444use std:: thread:: available_parallelism;
4545
4646/// Applies an optional projection to a [`SchemaRef`], returning the
@@ -923,10 +923,15 @@ pub fn combine_limit(
923923///
924924/// This is a wrapper around `std::thread::available_parallelism`, providing a default value
925925/// of `1` if the system's parallelism cannot be determined.
926+ ///
927+ /// The result is cached after the first call.
926928pub fn get_available_parallelism ( ) -> usize {
927- available_parallelism ( )
928- . unwrap_or ( NonZero :: new ( 1 ) . expect ( "literal value `1` shouldn't be zero" ) )
929- . get ( )
929+ static PARALLELISM : LazyLock < usize > = LazyLock :: new ( || {
930+ available_parallelism ( )
931+ . unwrap_or ( NonZero :: new ( 1 ) . expect ( "literal value `1` shouldn't be zero" ) )
932+ . get ( )
933+ } ) ;
934+ * PARALLELISM
930935}
931936
932937/// Converts a collection of function arguments into a fixed-size array of length N
You can’t perform that action at this time.
0 commit comments