From 9741df0f7792e03ff9c3d9ef7de060caa0f38b17 Mon Sep 17 00:00:00 2001 From: Gernot Bauer Date: Mon, 17 Jun 2024 16:25:29 +0200 Subject: [PATCH 1/2] Add optional allocators --- Cargo.toml | 6 ++++++ src/allocator.rs | 29 +++++++++++++++++++++++++++++ src/lib.rs | 1 + 3 files changed, 36 insertions(+) create mode 100644 src/allocator.rs diff --git a/Cargo.toml b/Cargo.toml index 2c15ff7ef..85e0352ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,12 @@ version = "0.21" features = ["extension-module", "abi3", "abi3-py37"] optional = true +[target.'cfg(all(any(not(target_family = "unix"), allocator = "mimalloc"), not(allocator = "default")))'.dependencies] +mimalloc = { version = "0.1", default-features = false } + +[target.'cfg(all(target_family = "unix", not(allocator = "mimalloc"), not(allocator = "default")))'.dependencies] +tikv-jemallocator = { version = "0.5", features = ["disable_initial_exec_tls"] } + [dev-dependencies] approx = "0.5" criterion = "0.5" diff --git a/src/allocator.rs b/src/allocator.rs new file mode 100644 index 000000000..d23c01b16 --- /dev/null +++ b/src/allocator.rs @@ -0,0 +1,29 @@ +#[cfg(all( + target_family = "unix", + not(allocator = "default"), + not(allocator = "mimalloc"), +))] +use tikv_jemallocator::Jemalloc; +#[cfg(all( + not(debug_assertions), + not(allocator = "default"), + any(not(target_family = "unix"), allocator = "mimalloc"), +))] +use mimalloc::MiMalloc; + +#[global_allocator] +#[cfg(all( + not(debug_assertions), + not(allocator = "mimalloc"), + not(allocator = "default"), + target_family = "unix", +))] +static ALLOC: Jemalloc = Jemalloc; + +#[global_allocator] +#[cfg(all( + not(debug_assertions), + not(allocator = "default"), + any(not(target_family = "unix"), allocator = "mimalloc"), +))] +static ALLOC: MiMalloc = MiMalloc; \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2f5659b2d..e79842064 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ #![warn(clippy::all)] #![allow(clippy::too_many_arguments)] +mod allocator; #[cfg(feature = "dft")] mod functional; #[cfg(feature = "dft")] From 594765af07d32d80a7267546cd310ff6b220c5c3 Mon Sep 17 00:00:00 2001 From: Gernot Bauer Date: Tue, 18 Jun 2024 10:44:37 +0200 Subject: [PATCH 2/2] Modify Cargo.toml so that criterion baseline can be used to compare changes --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 85e0352ba..c63188e13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ members = ["feos-core", "feos-dft", "feos-derive"] [lib] crate-type = ["rlib", "cdylib"] +bench = false [dependencies] quantity = { version = "0.8", optional = true }