Skip to content

Commit 7e2ebab

Browse files
authored
feat: add jemalloc as optional custom allocator (#1679)
* Add jemalloc, snmalloc, and tcmalloc. * Remove unnecessary check. rustc yelled at me if I tried to enable two. * Adjust snmalloc following instructions. * Remove tcmalloc since I can't get it to compile. * Fix jemalloc loading with dlopen. * Remove snmalloc.
1 parent bd0a60b commit 7e2ebab

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

native/Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/core/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ arrow = { workspace = true }
3939
parquet = { workspace = true, default-features = false, features = ["experimental"] }
4040
futures = { workspace = true }
4141
mimalloc = { version = "*", default-features = false, optional = true }
42+
tikv-jemallocator = { version = "0.6.0", optional = true, features = ["disable_initial_exec_tls"] }
4243
tokio = { version = "1", features = ["rt-multi-thread"] }
4344
async-trait = { workspace = true }
4445
log = "0.4"
@@ -51,13 +52,13 @@ snap = "1.1"
5152
# we disable default features in lz4_flex to force the use of the faster unsafe encoding and decoding implementation
5253
lz4_flex = { version = "0.11.3", default-features = false }
5354
zstd = "0.13.3"
54-
rand = { workspace = true}
55+
rand = { workspace = true }
5556
num = { workspace = true }
5657
bytes = { workspace = true }
5758
tempfile = "3.8.0"
5859
itertools = "0.14.0"
5960
paste = "1.0.14"
60-
datafusion = { workspace = true }
61+
datafusion = { workspace = true }
6162
once_cell = "1.18.0"
6263
regex = { workspace = true }
6364
crc32fast = "1.3.2"
@@ -80,7 +81,8 @@ datafusion-functions-nested = { version = "47.0.0" }
8081

8182
[features]
8283
default = []
83-
hdfs=["datafusion-comet-objectstore-hdfs"]
84+
hdfs = ["datafusion-comet-objectstore-hdfs"]
85+
jemalloc = ["tikv-jemallocator"]
8486

8587
# exclude optional packages from cargo machete verifications
8688
[package.metadata.cargo-machete]

native/core/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ use log4rs::{
3636
encode::pattern::PatternEncoder,
3737
Config,
3838
};
39+
use once_cell::sync::OnceCell;
40+
41+
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
42+
use tikv_jemallocator::Jemalloc;
43+
3944
#[cfg(feature = "mimalloc")]
4045
use mimalloc::MiMalloc;
41-
use once_cell::sync::OnceCell;
4246

4347
use errors::{try_unwrap_or_throw, CometError, CometResult};
4448

@@ -50,6 +54,10 @@ pub mod execution;
5054
mod jvm_bridge;
5155
pub mod parquet;
5256

57+
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
58+
#[global_allocator]
59+
static GLOBAL: Jemalloc = Jemalloc;
60+
5361
#[cfg(feature = "mimalloc")]
5462
#[global_allocator]
5563
static GLOBAL: MiMalloc = MiMalloc;

0 commit comments

Comments
 (0)