diff --git a/Cargo.toml b/Cargo.toml index 2c15ff7ef..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 } @@ -46,6 +47,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")]