From 4c676fe89594bdd8ed8e5ea5e8bbbc65eb319b6d Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Sat, 8 Mar 2025 01:33:18 +1100 Subject: [PATCH] c --- Cargo.lock | 10 ------- Cargo.toml | 1 - crates/polars-core/Cargo.toml | 1 - .../logical/categorical/string_cache.rs | 5 ++-- .../src/chunked_array/object/registry.rs | 6 ++-- .../src/chunked_array/temporal/mod.rs | 8 +++-- crates/polars-core/src/lib.rs | 13 ++++---- crates/polars-core/src/random.rs | 7 ++--- crates/polars-expr/Cargo.toml | 1 - .../polars-expr/src/state/execution_state.rs | 30 ++++++------------- crates/polars-io/Cargo.toml | 1 - .../polars-io/src/cloud/object_store_setup.rs | 7 ++--- crates/polars-io/src/cloud/options.rs | 8 ++--- crates/polars-io/src/file_cache/cache.rs | 5 ++-- crates/polars-io/src/file_cache/cache_lock.rs | 5 ++-- crates/polars-io/src/file_cache/entry.rs | 5 ++-- crates/polars-io/src/file_cache/utils.rs | 5 ++-- crates/polars-io/src/path_utils/mod.rs | 9 +++--- crates/polars-io/src/pl_async.rs | 8 ++--- crates/polars-io/src/utils/other.rs | 10 +++---- crates/polars-lazy/Cargo.toml | 1 - crates/polars-ops/Cargo.toml | 1 - crates/polars-pipe/Cargo.toml | 1 - .../sinks/group_by/generic/thread_local.rs | 5 ++-- crates/polars-plan/Cargo.toml | 1 - .../src/dsl/function_expr/plugin.rs | 6 ++-- .../src/dsl/function_expr/strings.rs | 8 ++--- crates/polars-python/Cargo.toml | 1 - crates/polars-time/Cargo.toml | 1 - .../src/chunkedarray/string/infer.rs | 12 +++++--- .../src/chunkedarray/string/strptime.rs | 13 ++++---- crates/polars-utils/Cargo.toml | 1 - crates/polars-utils/src/mem.rs | 4 +-- crates/polars-utils/src/mmap.rs | 4 +-- crates/polars-utils/src/python_function.rs | 5 ++-- crates/polars-utils/src/sys.rs | 5 ++-- 36 files changed, 90 insertions(+), 124 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53a9238a672e..1495ddbc43c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3070,7 +3070,6 @@ dependencies = [ "itoa", "ndarray", "num-traits", - "once_cell", "polars-arrow", "polars-compute", "polars-error", @@ -3137,7 +3136,6 @@ dependencies = [ "bitflags", "hashbrown 0.15.2", "num-traits", - "once_cell", "polars-arrow", "polars-compute", "polars-core", @@ -3183,7 +3181,6 @@ dependencies = [ "memmap2", "num-traits", "object_store", - "once_cell", "percent-encoding", "polars-arrow", "polars-core", @@ -3242,7 +3239,6 @@ dependencies = [ "either", "futures", "memchr", - "once_cell", "polars-arrow", "polars-compute", "polars-core", @@ -3303,7 +3299,6 @@ dependencies = [ "jsonpath_lib_polars_vendor", "memchr", "num-traits", - "once_cell", "polars-arrow", "polars-compute", "polars-core", @@ -3375,7 +3370,6 @@ dependencies = [ "futures", "hashbrown 0.15.2", "num-traits", - "once_cell", "polars-arrow", "polars-compute", "polars-core", @@ -3407,7 +3401,6 @@ dependencies = [ "libloading", "memmap2", "num-traits", - "once_cell", "percent-encoding", "polars-arrow", "polars-compute", @@ -3447,7 +3440,6 @@ dependencies = [ "ndarray", "num-traits", "numpy", - "once_cell", "polars", "polars-arrow", "polars-compute", @@ -3551,7 +3543,6 @@ dependencies = [ "chrono-tz", "now", "num-traits", - "once_cell", "polars-arrow", "polars-compute", "polars-core", @@ -3579,7 +3570,6 @@ dependencies = [ "libc", "memmap2", "num-traits", - "once_cell", "polars-error", "pyo3", "rand", diff --git a/Cargo.toml b/Cargo.toml index 95ddc4179664..cfa01ceea4e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,6 @@ ndarray = { version = "0.16", default-features = false } num-traits = "0.2" numpy = "0.23" object_store = { version = "0.11", default-features = false } -once_cell = "1" parking_lot = "0.12" percent-encoding = "2.3" pin-project-lite = "0.2" diff --git a/crates/polars-core/Cargo.toml b/crates/polars-core/Cargo.toml index 6acab666e96c..422b19eec39e 100644 --- a/crates/polars-core/Cargo.toml +++ b/crates/polars-core/Cargo.toml @@ -29,7 +29,6 @@ indexmap = { workspace = true } itoa = { workspace = true } ndarray = { workspace = true, optional = true } num-traits = { workspace = true } -once_cell = { workspace = true } rand = { workspace = true, optional = true, features = ["small_rng", "std"] } rand_distr = { workspace = true, optional = true } rayon = { workspace = true } diff --git a/crates/polars-core/src/chunked_array/logical/categorical/string_cache.rs b/crates/polars-core/src/chunked_array/logical/categorical/string_cache.rs index 6b8f0f65eb64..eb0c6633f81c 100644 --- a/crates/polars-core/src/chunked_array/logical/categorical/string_cache.rs +++ b/crates/polars-core/src/chunked_array/logical/categorical/string_cache.rs @@ -1,10 +1,9 @@ use std::hash::{Hash, Hasher}; use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; -use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::sync::{LazyLock, Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard}; use hashbrown::hash_table::Entry; use hashbrown::HashTable; -use once_cell::sync::Lazy; use polars_utils::aliases::PlRandomState; use polars_utils::pl_str::PlSmallStr; @@ -250,4 +249,4 @@ impl StringCache { } } -pub(crate) static STRING_CACHE: Lazy = Lazy::new(Default::default); +pub(crate) static STRING_CACHE: LazyLock = LazyLock::new(Default::default); diff --git a/crates/polars-core/src/chunked_array/object/registry.rs b/crates/polars-core/src/chunked_array/object/registry.rs index 7364cf0361d7..2b74c83c041b 100644 --- a/crates/polars-core/src/chunked_array/object/registry.rs +++ b/crates/polars-core/src/chunked_array/object/registry.rs @@ -5,11 +5,10 @@ use std::any::Any; use std::fmt::{Debug, Formatter}; use std::ops::Deref; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, LazyLock, RwLock}; use arrow::array::ArrayRef; use arrow::datatypes::ArrowDataType; -use once_cell::sync::Lazy; use polars_utils::pl_str::PlSmallStr; use crate::chunked_array::object::builder::ObjectChunkedBuilder; @@ -36,7 +35,8 @@ impl Debug for ObjectRegistry { } } -static GLOBAL_OBJECT_REGISTRY: Lazy>> = Lazy::new(Default::default); +static GLOBAL_OBJECT_REGISTRY: LazyLock>> = + LazyLock::new(Default::default); /// This trait can be registered, after which that global registration /// can be used to materialize object types diff --git a/crates/polars-core/src/chunked_array/temporal/mod.rs b/crates/polars-core/src/chunked_array/temporal/mod.rs index ad35aa90899e..e7a93543a10b 100644 --- a/crates/polars-core/src/chunked_array/temporal/mod.rs +++ b/crates/polars-core/src/chunked_array/temporal/mod.rs @@ -8,6 +8,9 @@ mod datetime; mod duration; #[cfg(feature = "dtype-time")] mod time; +#[cfg(feature = "timezones")] +use std::sync::LazyLock; + #[cfg(feature = "dtype-date")] use chrono::NaiveDate; use chrono::NaiveDateTime; @@ -16,8 +19,6 @@ use chrono::NaiveTime; #[cfg(feature = "timezones")] use chrono_tz::Tz; #[cfg(feature = "timezones")] -use once_cell::sync::Lazy; -#[cfg(feature = "timezones")] use polars_utils::pl_str::PlSmallStr; #[cfg(all(feature = "regex", feature = "timezones"))] use regex::Regex; @@ -38,7 +39,8 @@ static FIXED_OFFSET_PATTERN: &str = r#"(?x) $ "#; #[cfg(feature = "timezones")] -static FIXED_OFFSET_RE: Lazy = Lazy::new(|| Regex::new(FIXED_OFFSET_PATTERN).unwrap()); +static FIXED_OFFSET_RE: LazyLock = + LazyLock::new(|| Regex::new(FIXED_OFFSET_PATTERN).unwrap()); #[cfg(feature = "timezones")] pub fn validate_time_zone(tz: &str) -> PolarsResult<()> { diff --git a/crates/polars-core/src/lib.rs b/crates/polars-core/src/lib.rs index 33e3a4ee1413..9f45bf0c2a25 100644 --- a/crates/polars-core/src/lib.rs +++ b/crates/polars-core/src/lib.rs @@ -27,18 +27,17 @@ pub mod testing; #[cfg(test)] mod tests; -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; use std::time::{SystemTime, UNIX_EPOCH}; pub use datatypes::SchemaExtPl; pub use hashing::IdBuildHasher; -use once_cell::sync::Lazy; use rayon::{ThreadPool, ThreadPoolBuilder}; #[cfg(feature = "dtype-categorical")] pub use crate::chunked_array::logical::categorical::string_cache::*; -pub static PROCESS_ID: Lazy = Lazy::new(|| { +pub static PROCESS_ID: LazyLock = LazyLock::new(|| { SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() @@ -47,7 +46,7 @@ pub static PROCESS_ID: Lazy = Lazy::new(|| { // this is re-exported in utils for polars child crates #[cfg(not(target_family = "wasm"))] // only use this on non wasm targets -pub static POOL: Lazy = Lazy::new(|| { +pub static POOL: LazyLock = LazyLock::new(|| { let thread_name = std::env::var("POLARS_THREAD_NAME").unwrap_or_else(|_| "polars".to_string()); ThreadPoolBuilder::new() .num_threads( @@ -65,7 +64,7 @@ pub static POOL: Lazy = Lazy::new(|| { }); #[cfg(all(target_os = "emscripten", target_family = "wasm"))] // Use 1 rayon thread on emscripten -pub static POOL: Lazy = Lazy::new(|| { +pub static POOL: LazyLock = LazyLock::new(|| { ThreadPoolBuilder::new() .num_threads(1) .use_current_thread() @@ -74,10 +73,10 @@ pub static POOL: Lazy = Lazy::new(|| { }); #[cfg(all(not(target_os = "emscripten"), target_family = "wasm"))] // use this on other wasm targets -pub static POOL: Lazy = Lazy::new(|| polars_utils::wasm::Pool); +pub static POOL: LazyLock = LazyLock::new(|| polars_utils::wasm::Pool); // utility for the tests to ensure a single thread can execute -pub static SINGLE_LOCK: Lazy> = Lazy::new(|| Mutex::new(())); +pub static SINGLE_LOCK: LazyLock> = LazyLock::new(|| Mutex::new(())); /// Default length for a `.head()` call pub(crate) const HEAD_DEFAULT_LENGTH: usize = 10; diff --git a/crates/polars-core/src/random.rs b/crates/polars-core/src/random.rs index f6fd3c1f3978..1c88b05643a7 100644 --- a/crates/polars-core/src/random.rs +++ b/crates/polars-core/src/random.rs @@ -1,10 +1,9 @@ -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; -use once_cell::sync::Lazy; use rand::prelude::*; -static POLARS_GLOBAL_RNG_STATE: Lazy> = - Lazy::new(|| Mutex::new(SmallRng::from_entropy())); +static POLARS_GLOBAL_RNG_STATE: LazyLock> = + LazyLock::new(|| Mutex::new(SmallRng::from_entropy())); pub(crate) fn get_global_random_u64() -> u64 { POLARS_GLOBAL_RNG_STATE.lock().unwrap().next_u64() diff --git a/crates/polars-expr/Cargo.toml b/crates/polars-expr/Cargo.toml index bebab330750b..a8366c011463 100644 --- a/crates/polars-expr/Cargo.toml +++ b/crates/polars-expr/Cargo.toml @@ -14,7 +14,6 @@ arrow = { workspace = true } bitflags = { workspace = true } hashbrown = { workspace = true } num-traits = { workspace = true } -once_cell = { workspace = true } polars-compute = { workspace = true } polars-core = { workspace = true, features = ["lazy", "zip_with", "random"] } polars-io = { workspace = true, features = ["lazy"] } diff --git a/crates/polars-expr/src/state/execution_state.rs b/crates/polars-expr/src/state/execution_state.rs index 193e25ad9eb2..426138d83e4a 100644 --- a/crates/polars-expr/src/state/execution_state.rs +++ b/crates/polars-expr/src/state/execution_state.rs @@ -1,10 +1,9 @@ use std::borrow::Cow; use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU8, Ordering}; -use std::sync::{Mutex, RwLock}; +use std::sync::{Mutex, OnceLock, RwLock}; use std::time::Duration; use bitflags::bitflags; -use once_cell::sync::OnceCell; use polars_core::config::verbose; use polars_core::prelude::*; use polars_ops::prelude::ChunkJoinOptIds; @@ -101,12 +100,12 @@ impl From for StateFlags { } } -type CachedValue = Arc<(AtomicI64, OnceCell)>; +type CachedValue = Arc<(AtomicI64, OnceLock)>; /// State/ cache that is maintained during the Execution of the physical plan. pub struct ExecutionState { // cached by a `.cache` call and kept in memory for the duration of the plan. - df_cache: Arc>>, + df_cache: Arc>>, pub schema_cache: RwLock>, /// Used by Window Expressions to cache intermediate state pub window_cache: Arc, @@ -218,26 +217,15 @@ impl ExecutionState { } pub fn get_df_cache(&self, key: usize, cache_hits: u32) -> CachedValue { - let guard = self.df_cache.read().unwrap(); - - match guard.get(&key) { - Some(v) => v.clone(), - None => { - drop(guard); - let mut guard = self.df_cache.write().unwrap(); - - guard - .entry(key) - .or_insert_with(|| { - Arc::new((AtomicI64::new(cache_hits as i64), OnceCell::new())) - }) - .clone() - }, - } + let mut guard = self.df_cache.lock().unwrap(); + guard + .entry(key) + .or_insert_with(|| Arc::new((AtomicI64::new(cache_hits as i64), OnceLock::new()))) + .clone() } pub fn remove_df_cache(&self, key: usize) { - let mut guard = self.df_cache.write().unwrap(); + let mut guard = self.df_cache.lock().unwrap(); let _ = guard.remove(&key).unwrap(); } diff --git a/crates/polars-io/Cargo.toml b/crates/polars-io/Cargo.toml index cb74360f62f7..3bde2ee8593f 100644 --- a/crates/polars-io/Cargo.toml +++ b/crates/polars-io/Cargo.toml @@ -35,7 +35,6 @@ memchr = { workspace = true } memmap = { workspace = true } num-traits = { workspace = true } object_store = { workspace = true, optional = true } -once_cell = { workspace = true } percent-encoding = { workspace = true } pyo3 = { workspace = true, optional = true } rayon = { workspace = true } diff --git a/crates/polars-io/src/cloud/object_store_setup.rs b/crates/polars-io/src/cloud/object_store_setup.rs index 08345b69d94a..0e638841bdd4 100644 --- a/crates/polars-io/src/cloud/object_store_setup.rs +++ b/crates/polars-io/src/cloud/object_store_setup.rs @@ -1,8 +1,7 @@ -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use object_store::local::LocalFileSystem; use object_store::ObjectStore; -use once_cell::sync::Lazy; use polars_core::config::{self, verbose_print_sensitive}; use polars_error::{polars_bail, to_compute_err, PolarsError, PolarsResult}; use polars_utils::aliases::PlHashMap; @@ -18,8 +17,8 @@ use crate::cloud::CloudConfig; /// get rate limited when querying the DNS (can take up to 5s). /// Other reasons are connection pools that must be shared between as much as possible. #[allow(clippy::type_complexity)] -static OBJECT_STORE_CACHE: Lazy, PolarsObjectStore>>> = - Lazy::new(Default::default); +static OBJECT_STORE_CACHE: LazyLock, PolarsObjectStore>>> = + LazyLock::new(Default::default); #[allow(dead_code)] fn err_missing_feature(feature: &str, scheme: &str) -> PolarsResult> { diff --git a/crates/polars-io/src/cloud/options.rs b/crates/polars-io/src/cloud/options.rs index 399133a75269..8ad03dfd5c9b 100644 --- a/crates/polars-io/src/cloud/options.rs +++ b/crates/polars-io/src/cloud/options.rs @@ -3,6 +3,7 @@ use std::io::Read; #[cfg(feature = "aws")] use std::path::Path; use std::str::FromStr; +use std::sync::LazyLock; #[cfg(feature = "aws")] use object_store::aws::AmazonS3Builder; @@ -20,7 +21,6 @@ pub use object_store::gcp::GoogleConfigKey; use object_store::ClientOptions; #[cfg(any(feature = "aws", feature = "gcp", feature = "azure"))] use object_store::{BackoffConfig, RetryConfig}; -use once_cell::sync::Lazy; use polars_error::*; #[cfg(feature = "aws")] use polars_utils::cache::FastFixedCache; @@ -41,11 +41,11 @@ use crate::file_cache::get_env_file_cache_ttl; use crate::pl_async::with_concurrency_budget; #[cfg(feature = "aws")] -static BUCKET_REGION: Lazy< +static BUCKET_REGION: LazyLock< std::sync::Mutex< FastFixedCache, >, -> = Lazy::new(|| std::sync::Mutex::new(FastFixedCache::new(32))); +> = LazyLock::new(|| std::sync::Mutex::new(FastFixedCache::new(32))); /// The type of the config keys must satisfy the following requirements: /// 1. must be easily collected into a HashMap, the type required by the object_crate API. @@ -91,7 +91,7 @@ impl Default for CloudOptions { impl CloudOptions { pub fn default_static_ref() -> &'static Self { - static DEFAULT: Lazy = Lazy::new(|| CloudOptions { + static DEFAULT: LazyLock = LazyLock::new(|| CloudOptions { max_retries: 2, #[cfg(feature = "file_cache")] file_cache_ttl: get_env_file_cache_ttl(), diff --git a/crates/polars-io/src/file_cache/cache.rs b/crates/polars-io/src/file_cache/cache.rs index e23c65af7e77..223c70f9e9ef 100644 --- a/crates/polars-io/src/file_cache/cache.rs +++ b/crates/polars-io/src/file_cache/cache.rs @@ -1,8 +1,7 @@ use std::path::Path; use std::sync::atomic::AtomicU64; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, LazyLock, RwLock}; -use once_cell::sync::Lazy; use polars_core::config; use polars_error::PolarsResult; use polars_utils::aliases::PlHashMap; @@ -13,7 +12,7 @@ use super::file_fetcher::FileFetcher; use super::utils::FILE_CACHE_PREFIX; use crate::path_utils::{ensure_directory_init, is_cloud_url}; -pub static FILE_CACHE: Lazy = Lazy::new(|| { +pub static FILE_CACHE: LazyLock = LazyLock::new(|| { let prefix = FILE_CACHE_PREFIX.as_ref(); let prefix = Arc::::from(prefix); diff --git a/crates/polars-io/src/file_cache/cache_lock.rs b/crates/polars-io/src/file_cache/cache_lock.rs index 0b1f87b6b961..bf5b279c4b25 100644 --- a/crates/polars-io/src/file_cache/cache_lock.rs +++ b/crates/polars-io/src/file_cache/cache_lock.rs @@ -1,14 +1,13 @@ use std::sync::atomic::AtomicBool; -use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::sync::{Arc, LazyLock, RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::time::Duration; use fs4::fs_std::FileExt; -use once_cell::sync::Lazy; use super::utils::FILE_CACHE_PREFIX; use crate::pl_async; -pub(super) static GLOBAL_FILE_CACHE_LOCK: Lazy = Lazy::new(|| { +pub(super) static GLOBAL_FILE_CACHE_LOCK: LazyLock = LazyLock::new(|| { let path = FILE_CACHE_PREFIX.join(".process-lock"); let file = std::fs::OpenOptions::new() diff --git a/crates/polars-io/src/file_cache/entry.rs b/crates/polars-io/src/file_cache/entry.rs index bf86b0c2a547..61bf0ceeb166 100644 --- a/crates/polars-io/src/file_cache/entry.rs +++ b/crates/polars-io/src/file_cache/entry.rs @@ -1,10 +1,9 @@ use std::io::{Seek, SeekFrom}; use std::path::{Path, PathBuf}; use std::sync::atomic::AtomicU64; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, LazyLock, Mutex}; use fs4::fs_std::FileExt; -use once_cell::sync::Lazy; use polars_core::config; use polars_error::{polars_bail, to_compute_err, PolarsError, PolarsResult}; @@ -156,7 +155,7 @@ impl Inner { // * Some(true) => always raise // * Some(false) => never raise // * None => do not raise if fallocate() is not permitted, otherwise raise. - static RAISE_ALLOC_ERROR: Lazy> = Lazy::new(|| { + static RAISE_ALLOC_ERROR: LazyLock> = LazyLock::new(|| { let v = match std::env::var("POLARS_IGNORE_FILE_CACHE_ALLOCATE_ERROR").as_deref() { Ok("1") => Some(false), Ok("0") => Some(true), diff --git a/crates/polars-io/src/file_cache/utils.rs b/crates/polars-io/src/file_cache/utils.rs index 682e191df124..5790bffde57b 100644 --- a/crates/polars-io/src/file_cache/utils.rs +++ b/crates/polars-io/src/file_cache/utils.rs @@ -1,8 +1,7 @@ use std::path::Path; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use std::time::UNIX_EPOCH; -use once_cell::sync::Lazy; use polars_error::{PolarsError, PolarsResult}; use super::cache::{get_env_file_cache_ttl, FILE_CACHE}; @@ -12,7 +11,7 @@ use crate::cloud::{build_object_store, object_path_from_str, CloudLocation, Clou use crate::path_utils::{ensure_directory_init, is_cloud_url, POLARS_TEMP_DIR_BASE_PATH}; use crate::pl_async; -pub static FILE_CACHE_PREFIX: Lazy> = Lazy::new(|| { +pub static FILE_CACHE_PREFIX: LazyLock> = LazyLock::new(|| { let path = POLARS_TEMP_DIR_BASE_PATH .join("file-cache/") .into_boxed_path(); diff --git a/crates/polars-io/src/path_utils/mod.rs b/crates/polars-io/src/path_utils/mod.rs index a8a6bf7c567b..341a3ca95a79 100644 --- a/crates/polars-io/src/path_utils/mod.rs +++ b/crates/polars-io/src/path_utils/mod.rs @@ -1,8 +1,7 @@ use std::collections::VecDeque; use std::path::{Path, PathBuf}; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; -use once_cell::sync::Lazy; use polars_core::config; use polars_core::error::{polars_bail, to_compute_err, PolarsError, PolarsResult}; use polars_utils::pl_str::PlSmallStr; @@ -13,7 +12,7 @@ mod hugging_face; use crate::cloud::CloudOptions; -pub static POLARS_TEMP_DIR_BASE_PATH: Lazy> = Lazy::new(|| { +pub static POLARS_TEMP_DIR_BASE_PATH: LazyLock> = LazyLock::new(|| { (|| { let verbose = config::verbose(); @@ -139,8 +138,8 @@ pub fn resolve_homedir(path: &dyn AsRef) -> PathBuf { path.into() } -static CLOUD_URL: Lazy = - Lazy::new(|| Regex::new(r"^(s3a?|gs|gcs|file|abfss?|azure|az|adl|https?|hf)://").unwrap()); +static CLOUD_URL: LazyLock = + LazyLock::new(|| Regex::new(r"^(s3a?|gs|gcs|file|abfss?|azure|az|adl|https?|hf)://").unwrap()); /// Check if the path is a cloud url. pub fn is_cloud_url>(p: P) -> bool { diff --git a/crates/polars-io/src/pl_async.rs b/crates/polars-io/src/pl_async.rs index 0147514e0384..4bebe5ad67f2 100644 --- a/crates/polars-io/src/pl_async.rs +++ b/crates/polars-io/src/pl_async.rs @@ -2,8 +2,8 @@ use std::error::Error; use std::future::Future; use std::ops::Deref; use std::sync::atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering}; +use std::sync::LazyLock; -use once_cell::sync::Lazy; use polars_core::config::{self, verbose}; use polars_core::POOL; use tokio::runtime::{Builder, Runtime}; @@ -14,7 +14,7 @@ pub(super) const MAX_BUDGET_PER_REQUEST: usize = 10; /// Used to determine chunks when splitting large ranges, or combining small /// ranges. -static DOWNLOAD_CHUNK_SIZE: Lazy = Lazy::new(|| { +static DOWNLOAD_CHUNK_SIZE: LazyLock = LazyLock::new(|| { let v: usize = std::env::var("POLARS_DOWNLOAD_CHUNK_SIZE") .as_deref() .map(|x| x.parse().expect("integer")) @@ -31,7 +31,7 @@ pub(super) fn get_download_chunk_size() -> usize { *DOWNLOAD_CHUNK_SIZE } -static UPLOAD_CHUNK_SIZE: Lazy = Lazy::new(|| { +static UPLOAD_CHUNK_SIZE: LazyLock = LazyLock::new(|| { let v: usize = std::env::var("POLARS_UPLOAD_CHUNK_SIZE") .as_deref() .map(|x| x.parse().expect("integer")) @@ -364,7 +364,7 @@ impl RuntimeManager { } } -static RUNTIME: Lazy = Lazy::new(RuntimeManager::new); +static RUNTIME: LazyLock = LazyLock::new(RuntimeManager::new); pub fn get_runtime() -> &'static RuntimeManager { RUNTIME.deref() diff --git a/crates/polars-io/src/utils/other.rs b/crates/polars-io/src/utils/other.rs index a3529b9d7937..ac4fef08a6f1 100644 --- a/crates/polars-io/src/utils/other.rs +++ b/crates/polars-io/src/utils/other.rs @@ -1,8 +1,8 @@ use std::io::Read; #[cfg(target_os = "emscripten")] use std::io::{Seek, SeekFrom}; +use std::sync::LazyLock; -use once_cell::sync::Lazy; use polars_core::prelude::*; use polars_utils::mmap::{MMapSemaphore, MemSlice}; use regex::{Regex, RegexBuilder}; @@ -153,17 +153,17 @@ pub fn overwrite_schema(schema: &mut Schema, overwriting_schema: &Schema) -> Pol Ok(()) } -pub static FLOAT_RE: Lazy = Lazy::new(|| { +pub static FLOAT_RE: LazyLock = LazyLock::new(|| { Regex::new(r"^[-+]?((\d*\.\d+)([eE][-+]?\d+)?|inf|NaN|(\d+)[eE][-+]?\d+|\d+\.)$").unwrap() }); -pub static FLOAT_RE_DECIMAL: Lazy = Lazy::new(|| { +pub static FLOAT_RE_DECIMAL: LazyLock = LazyLock::new(|| { Regex::new(r"^[-+]?((\d*,\d+)([eE][-+]?\d+)?|inf|NaN|(\d+)[eE][-+]?\d+|\d+,)$").unwrap() }); -pub static INTEGER_RE: Lazy = Lazy::new(|| Regex::new(r"^-?(\d+)$").unwrap()); +pub static INTEGER_RE: LazyLock = LazyLock::new(|| Regex::new(r"^-?(\d+)$").unwrap()); -pub static BOOLEAN_RE: Lazy = Lazy::new(|| { +pub static BOOLEAN_RE: LazyLock = LazyLock::new(|| { RegexBuilder::new(r"^(true|false)$") .case_insensitive(true) .build() diff --git a/crates/polars-lazy/Cargo.toml b/crates/polars-lazy/Cargo.toml index e427e44019f9..bbffabc69aae 100644 --- a/crates/polars-lazy/Cargo.toml +++ b/crates/polars-lazy/Cargo.toml @@ -29,7 +29,6 @@ ahash = { workspace = true } bitflags = { workspace = true } either = { workspace = true } memchr = { workspace = true } -once_cell = { workspace = true } pyo3 = { workspace = true, optional = true } rayon = { workspace = true } tokio = { workspace = true, optional = true } diff --git a/crates/polars-ops/Cargo.toml b/crates/polars-ops/Cargo.toml index 1034bf0db3f4..aca43eec83ad 100644 --- a/crates/polars-ops/Cargo.toml +++ b/crates/polars-ops/Cargo.toml @@ -30,7 +30,6 @@ hex = { workspace = true, optional = true } indexmap = { workspace = true } memchr = { workspace = true } num-traits = { workspace = true } -once_cell = { workspace = true } rand = { workspace = true, optional = true, features = ["small_rng", "std"] } rand_distr = { workspace = true, optional = true } rayon = { workspace = true } diff --git a/crates/polars-pipe/Cargo.toml b/crates/polars-pipe/Cargo.toml index d8cd3f379adf..2d5bbf4ba0e1 100644 --- a/crates/polars-pipe/Cargo.toml +++ b/crates/polars-pipe/Cargo.toml @@ -11,7 +11,6 @@ description = "Lazy query engine for the Polars DataFrame library" [dependencies] arrow = { workspace = true } futures = { workspace = true, optional = true } -once_cell = { workspace = true } polars-compute = { workspace = true } polars-core = { workspace = true, features = ["lazy", "zip_with", "random", "rows"] } polars-expr = { workspace = true } diff --git a/crates/polars-pipe/src/executors/sinks/group_by/generic/thread_local.rs b/crates/polars-pipe/src/executors/sinks/group_by/generic/thread_local.rs index 4c863e069802..c1e2c7ad6b07 100644 --- a/crates/polars-pipe/src/executors/sinks/group_by/generic/thread_local.rs +++ b/crates/polars-pipe/src/executors/sinks/group_by/generic/thread_local.rs @@ -1,5 +1,6 @@ +use std::sync::LazyLock; + use arrow::array::MutableBinaryArray; -use once_cell::sync::Lazy; use polars_utils::hashing::hash_to_partition; use super::*; @@ -7,7 +8,7 @@ use crate::pipeline::PARTITION_SIZE; const OB_SIZE: usize = 2048; -static SPILL_SIZE: Lazy = Lazy::new(|| { +static SPILL_SIZE: LazyLock = LazyLock::new(|| { std::env::var("POLARS_STREAMING_GROUPBY_SPILL_SIZE") .map(|v| v.parse::().unwrap()) .unwrap_or(10_000) diff --git a/crates/polars-plan/Cargo.toml b/crates/polars-plan/Cargo.toml index 811ad6006e76..b78b2975c61a 100644 --- a/crates/polars-plan/Cargo.toml +++ b/crates/polars-plan/Cargo.toml @@ -35,7 +35,6 @@ futures = { workspace = true, optional = true } hashbrown = { workspace = true } memmap = { workspace = true } num-traits = { workspace = true } -once_cell = { workspace = true } percent-encoding = { workspace = true } pyo3 = { workspace = true, optional = true } rayon = { workspace = true } diff --git a/crates/polars-plan/src/dsl/function_expr/plugin.rs b/crates/polars-plan/src/dsl/function_expr/plugin.rs index f11cca8863ec..36d634f1dcba 100644 --- a/crates/polars-plan/src/dsl/function_expr/plugin.rs +++ b/crates/polars-plan/src/dsl/function_expr/plugin.rs @@ -1,14 +1,14 @@ use std::ffi::CStr; -use std::sync::RwLock; +use std::sync::{LazyLock, RwLock}; use arrow::ffi::{import_field_from_c, ArrowSchema}; use libloading::Library; -use once_cell::sync::Lazy; use super::*; type PluginAndVersion = (Library, u16, u16); -static LOADED: Lazy>> = Lazy::new(Default::default); +static LOADED: LazyLock>> = + LazyLock::new(Default::default); fn get_lib(lib: &str) -> PolarsResult<&'static PluginAndVersion> { let lib_map = LOADED.read().unwrap(); diff --git a/crates/polars-plan/src/dsl/function_expr/strings.rs b/crates/polars-plan/src/dsl/function_expr/strings.rs index f3d93605b501..57a6d74ea629 100644 --- a/crates/polars-plan/src/dsl/function_expr/strings.rs +++ b/crates/polars-plan/src/dsl/function_expr/strings.rs @@ -1,9 +1,9 @@ use std::borrow::Cow; +#[cfg(feature = "timezones")] +use std::sync::LazyLock; use arrow::legacy::utils::CustomIterTools; #[cfg(feature = "timezones")] -use once_cell::sync::Lazy; -#[cfg(feature = "timezones")] use polars_core::chunked_array::temporal::validate_time_zone; use polars_core::utils::handle_casting_failures; #[cfg(feature = "dtype-struct")] @@ -17,8 +17,8 @@ use super::*; use crate::{map, map_as_slice}; #[cfg(all(feature = "regex", feature = "timezones"))] -static TZ_AWARE_RE: Lazy = - Lazy::new(|| Regex::new(r"(%z)|(%:z)|(%::z)|(%:::z)|(%#z)|(^%\+$)").unwrap()); +static TZ_AWARE_RE: LazyLock = + LazyLock::new(|| Regex::new(r"(%z)|(%:z)|(%::z)|(%:::z)|(%#z)|(^%\+$)").unwrap()); #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, PartialEq, Debug, Eq, Hash)] diff --git a/crates/polars-python/Cargo.toml b/crates/polars-python/Cargo.toml index c5a63f830c6f..ce4192171508 100644 --- a/crates/polars-python/Cargo.toml +++ b/crates/polars-python/Cargo.toml @@ -41,7 +41,6 @@ libc = { workspace = true } ndarray = { workspace = true } num-traits = { workspace = true } numpy = { workspace = true } -once_cell = { workspace = true } pyo3 = { workspace = true, features = ["abi3-py39", "chrono", "chrono-tz", "multiple-pymethods"] } rayon = { workspace = true } recursive = { workspace = true } diff --git a/crates/polars-time/Cargo.toml b/crates/polars-time/Cargo.toml index 62577bdb41cf..a506bf1547fb 100644 --- a/crates/polars-time/Cargo.toml +++ b/crates/polars-time/Cargo.toml @@ -22,7 +22,6 @@ chrono = { workspace = true } chrono-tz = { workspace = true, optional = true } now = { version = "0.1" } num-traits = { workspace = true } -once_cell = { workspace = true } rayon = { workspace = true } regex = { workspace = true } serde = { workspace = true, optional = true } diff --git a/crates/polars-time/src/chunkedarray/string/infer.rs b/crates/polars-time/src/chunkedarray/string/infer.rs index ea5be7b112a1..a4e471ce4581 100644 --- a/crates/polars-time/src/chunkedarray/string/infer.rs +++ b/crates/polars-time/src/chunkedarray/string/infer.rs @@ -1,7 +1,8 @@ +use std::sync::LazyLock; + use arrow::array::PrimitiveArray; use chrono::format::ParseErrorKind; use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime}; -use once_cell::sync::Lazy; use polars_core::prelude::*; use regex::Regex; @@ -36,7 +37,8 @@ const DATETIME_DMY_PATTERN: &str = r#"(?x) $ "#; -static DATETIME_DMY_RE: Lazy = Lazy::new(|| Regex::new(DATETIME_DMY_PATTERN).unwrap()); +static DATETIME_DMY_RE: LazyLock = + LazyLock::new(|| Regex::new(DATETIME_DMY_PATTERN).unwrap()); const DATETIME_YMD_PATTERN: &str = r#"(?x) ^ ['"]? # optional quotes @@ -61,7 +63,8 @@ const DATETIME_YMD_PATTERN: &str = r#"(?x) ['"]? # optional quotes $ "#; -static DATETIME_YMD_RE: Lazy = Lazy::new(|| Regex::new(DATETIME_YMD_PATTERN).unwrap()); +static DATETIME_YMD_RE: LazyLock = + LazyLock::new(|| Regex::new(DATETIME_YMD_PATTERN).unwrap()); const DATETIME_YMDZ_PATTERN: &str = r#"(?x) ^ ['"]? # optional quotes @@ -92,7 +95,8 @@ const DATETIME_YMDZ_PATTERN: &str = r#"(?x) ['"]? # optional quotes $ "#; -static DATETIME_YMDZ_RE: Lazy = Lazy::new(|| Regex::new(DATETIME_YMDZ_PATTERN).unwrap()); +static DATETIME_YMDZ_RE: LazyLock = + LazyLock::new(|| Regex::new(DATETIME_YMDZ_PATTERN).unwrap()); impl Pattern { pub fn is_inferable(&self, val: &str) -> bool { diff --git a/crates/polars-time/src/chunkedarray/string/strptime.rs b/crates/polars-time/src/chunkedarray/string/strptime.rs index 69bb7bb9f006..fe073efee302 100644 --- a/crates/polars-time/src/chunkedarray/string/strptime.rs +++ b/crates/polars-time/src/chunkedarray/string/strptime.rs @@ -1,16 +1,17 @@ //! Much more opinionated, but also much faster strptrime than the one given in Chrono. //! +use std::sync::LazyLock; + use chrono::{NaiveDate, NaiveDateTime}; -use once_cell::sync::Lazy; use regex::Regex; use crate::chunkedarray::{polars_bail, PolarsResult}; -static HOUR_PATTERN: Lazy = Lazy::new(|| Regex::new(r"%[_-]?[HkIl]").unwrap()); -static MINUTE_PATTERN: Lazy = Lazy::new(|| Regex::new(r"%[_-]?M").unwrap()); -static SECOND_PATTERN: Lazy = Lazy::new(|| Regex::new(r"%[_-]?S").unwrap()); -static TWELVE_HOUR_PATTERN: Lazy = Lazy::new(|| Regex::new(r"%[_-]?[Il]").unwrap()); -static MERIDIEM_PATTERN: Lazy = Lazy::new(|| Regex::new(r"%[_-]?[pP]").unwrap()); +static HOUR_PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"%[_-]?[HkIl]").unwrap()); +static MINUTE_PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"%[_-]?M").unwrap()); +static SECOND_PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"%[_-]?S").unwrap()); +static TWELVE_HOUR_PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"%[_-]?[Il]").unwrap()); +static MERIDIEM_PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"%[_-]?[pP]").unwrap()); #[inline] fn update_and_parse( diff --git a/crates/polars-utils/Cargo.toml b/crates/polars-utils/Cargo.toml index 650e80083ffe..7e5ad223f53a 100644 --- a/crates/polars-utils/Cargo.toml +++ b/crates/polars-utils/Cargo.toml @@ -20,7 +20,6 @@ indexmap = { workspace = true } libc = { workspace = true } memmap = { workspace = true, optional = true } num-traits = { workspace = true } -once_cell = { workspace = true } polars-error = { workspace = true } pyo3 = { workspace = true, optional = true } rand = { workspace = true } diff --git a/crates/polars-utils/src/mem.rs b/crates/polars-utils/src/mem.rs index 20bf08bf4784..931c98341674 100644 --- a/crates/polars-utils/src/mem.rs +++ b/crates/polars-utils/src/mem.rs @@ -8,8 +8,8 @@ pub unsafe fn to_mutable_slice(s: &[T]) -> &mut [T] { } pub mod prefetch { - use once_cell::sync::Lazy; - static PAGE_SIZE: Lazy = Lazy::new(|| { + use std::sync::LazyLock; + static PAGE_SIZE: LazyLock = LazyLock::new(|| { #[cfg(target_family = "unix")] unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize diff --git a/crates/polars-utils/src/mmap.rs b/crates/polars-utils/src/mmap.rs index 922e78d30cc2..f0ac0e4b56f2 100644 --- a/crates/polars-utils/src/mmap.rs +++ b/crates/polars-utils/src/mmap.rs @@ -268,9 +268,9 @@ impl io::Seek for MemReader { // Use a btree as it uses less memory than a hashmap and this thing never shrinks. // Write handle in Windows is exclusive, so this is only necessary in Unix. #[cfg(target_family = "unix")] -static MEMORY_MAPPED_FILES: once_cell::sync::Lazy< +static MEMORY_MAPPED_FILES: std::sync::LazyLock< std::sync::Mutex>, -> = once_cell::sync::Lazy::new(|| std::sync::Mutex::new(Default::default())); +> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default())); #[derive(Debug)] pub struct MMapSemaphore { diff --git a/crates/polars-utils/src/python_function.rs b/crates/polars-utils/src/python_function.rs index e3b0bf6645e5..dbb8360ceea6 100644 --- a/crates/polars-utils/src/python_function.rs +++ b/crates/polars-utils/src/python_function.rs @@ -125,7 +125,8 @@ mod _serde_impls { #[cfg(feature = "serde")] mod serde_wrap { - use once_cell::sync::Lazy; + use std::sync::LazyLock; + use polars_error::PolarsResult; use super::*; @@ -134,7 +135,7 @@ mod serde_wrap { pub const SERDE_MAGIC_BYTE_MARK: &[u8] = "PLPYFN".as_bytes(); /// [minor, micro] - pub static PYTHON3_VERSION: Lazy<[u8; 2]> = Lazy::new(super::get_python3_version); + pub static PYTHON3_VERSION: LazyLock<[u8; 2]> = LazyLock::new(super::get_python3_version); /// Serializes a Python object without additional system metadata. This is intended to be used /// together with `PySerializeWrap`, which attaches e.g. Python version metadata. diff --git a/crates/polars-utils/src/sys.rs b/crates/polars-utils/src/sys.rs index 9b43d0ac664c..b2a4bee748bc 100644 --- a/crates/polars-utils/src/sys.rs +++ b/crates/polars-utils/src/sys.rs @@ -1,6 +1,5 @@ -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; -use once_cell::sync::Lazy; use sysinfo::System; /// Startup system is expensive, so we do it once @@ -20,6 +19,6 @@ impl MemInfo { } } -pub static MEMINFO: Lazy = Lazy::new(|| MemInfo { +pub static MEMINFO: LazyLock = LazyLock::new(|| MemInfo { sys: Mutex::new(System::new()), });