Skip to content

Commit 4f21176

Browse files
committed
Switch to jemalloc as default?
1 parent cd0a981 commit 4f21176

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

minimappers2/Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ crate-type = ["cdylib", "rlib"]
1010
[dependencies]
1111
minimap2 = { version = "0.1.23", features = ["simde"], path = ".." }
1212
crossbeam = "0.8.4"
13-
mimalloc = {version = "0.1", default-features = false }
14-
15-
pyo3 = { version = "0.22" }
13+
pyo3 = { version = "0.22", features = ["abi3-py39", "chrono", "extension-module"] }
1614
polars = "0.45"
1715
pyo3-polars = "0.19"
1816

17+
[target.'cfg(all(any(not(target_family = "unix"), target_os = "emscripten", allocator = "mimalloc"), not(allocator = "default")))'.dependencies]
18+
mimalloc = { version = "0.1", default-features = false }
19+
20+
# Feature background_threads is unsupported on MacOS (https://github.com/jemalloc/jemalloc/issues/843).
21+
[target.'cfg(all(target_family = "unix", not(target_os = "macos"), not(target_os = "emscripten"), not(allocator = "mimalloc"), not(allocator = "default")))'.dependencies]
22+
jemallocator = { version = "0.5", features = ["disable_initial_exec_tls", "background_threads"] }
23+
24+
[target.'cfg(all(target_family = "unix", target_os = "macos", not(allocator = "mimalloc"), not(allocator = "default")))'.dependencies]
25+
jemallocator = { version = "0.5", features = ["disable_initial_exec_tls"] }
26+
1927
[profile.release]
2028
opt-level = 3
2129
lto = "fat"

minimappers2/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
println!("cargo::rustc-check-cfg=cfg(allocator, values(\"default\", \"mimalloc\"))");
3+
println!(
4+
"cargo:rustc-env=TARGET={}",
5+
std::env::var("TARGET").unwrap()
6+
);
7+
}

minimappers2/src/lib.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,52 @@ use std::num::NonZeroI32;
22
use std::sync::{Arc, Mutex};
33

44
use crossbeam::queue::ArrayQueue;
5-
use mimalloc::MiMalloc;
65
use minimap2::*;
76

87
use polars::{df, prelude::*};
98
use pyo3::prelude::*;
109
use pyo3_polars::{error::PyPolarsErr, PyDataFrame};
1110

11+
#[cfg(all(
12+
target_family = "unix",
13+
not(target_os = "emscripten"),
14+
not(allocator = "default"),
15+
not(allocator = "mimalloc"),
16+
))]
17+
use jemallocator::Jemalloc;
18+
#[cfg(all(
19+
not(debug_assertions),
20+
not(allocator = "default"),
21+
any(
22+
not(target_family = "unix"),
23+
target_os = "emscripten",
24+
allocator = "mimalloc"
25+
),
26+
))]
27+
use mimalloc::MiMalloc;
28+
1229
#[global_allocator]
13-
static GLOBAL: MiMalloc = MiMalloc;
30+
#[cfg(all(
31+
not(debug_assertions),
32+
not(allocator = "mimalloc"),
33+
not(allocator = "default"),
34+
target_family = "unix",
35+
not(target_os = "emscripten"),
36+
))]
37+
static ALLOC: Jemalloc = Jemalloc;
38+
39+
#[global_allocator]
40+
#[cfg(all(
41+
not(debug_assertions),
42+
not(allocator = "default"),
43+
any(
44+
not(target_family = "unix"),
45+
target_os = "emscripten",
46+
allocator = "mimalloc"
47+
),
48+
))]
49+
static ALLOC: MiMalloc = MiMalloc;
50+
1451

1552
mod multithreading;
1653

0 commit comments

Comments
 (0)