Skip to content

Commit b03380d

Browse files
committed
chore: use custom global alloc
Signed-off-by: ion-elgreco <[email protected]>
1 parent 0718510 commit b03380d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

python/.cargo/config.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ rustflags = [
88
rustflags = [
99
"-C", "link-arg=-undefined",
1010
"-C", "link-arg=dynamic_lookup",
11-
]
11+
]
12+
13+
# Custom jemalloc conf, ref https://github.com/jemalloc/jemalloc/issues/2688
14+
[env]
15+
JEMALLOC_SYS_WITH_MALLOC_CONF = "dirty_decay_ms:500,muzzy_decay_ms:-1"

python/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ reqwest = { version = "*", features = ["native-tls-vendored"] }
4747

4848
deltalake-mount = { path = "../crates/mount" }
4949

50+
# Non-unix or emscripten os
51+
[target.'cfg(any(not(target_family = "unix"), target_os = "emscripten"))'.dependencies]
52+
mimalloc = { version = "0.1", default-features = false }
53+
54+
# Unix (excluding macOS & emscripten) → jemalloc
55+
[target.'cfg(all(target_family = "unix", not(target_os = "macos"), not(target_os = "emscripten")))'.dependencies]
56+
jemallocator = { version = "0.5", features = ["disable_initial_exec_tls", "background_threads"] }
57+
58+
# macOS → jemalloc (without background_threads) (https://github.com/jemalloc/jemalloc/issues/843)
59+
[target.'cfg(all(target_family = "unix", target_os = "macos"))'.dependencies]
60+
jemallocator = { version = "0.5", features = ["disable_initial_exec_tls"] }
61+
5062
[dependencies.pyo3]
5163
version = "0.22.6"
5264
features = ["extension-module", "abi3", "abi3-py39", "gil-refs"]

python/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ use crate::query::PyQueryBuilder;
7979
use crate::schema::{schema_to_pyobject, Field};
8080
use crate::utils::rt;
8181

82+
#[cfg(all(target_family = "unix", not(target_os = "emscripten")))]
83+
use jemallocator::Jemalloc;
84+
85+
#[cfg(all(any(not(target_family = "unix"), target_os = "emscripten")))]
86+
use mimalloc::MiMalloc;
87+
88+
#[global_allocator]
89+
#[cfg(all(target_family = "unix", not(target_os = "emscripten")))]
90+
static ALLOC: Jemalloc = Jemalloc;
91+
92+
#[global_allocator]
93+
#[cfg(all(any(not(target_family = "unix"), target_os = "emscripten")))]
94+
static ALLOC: MiMalloc = MiMalloc;
95+
8296
#[derive(FromPyObject)]
8397
enum PartitionFilterValue {
8498
Single(PyBackedStr),

0 commit comments

Comments
 (0)