Skip to content

Commit 459fa01

Browse files
committed
Add more memory allocator
1 parent efb8206 commit 459fa01

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

nautilus_core/Cargo.lock

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nautilus_core/common/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ ustr = { workspace = true }
3434
uuid = { workspace = true }
3535
bincode = "1.3.3"
3636
sysinfo = "0.33.1"
37+
mimalloc = { version = "0.1", optional = true }
38+
39+
# Jemallocator does not work on aarch64 with musl
40+
[target.'cfg(all(target_family="unix", not(all(target_arch = "aarch64", target_env = "musl"))))'.dependencies]
41+
tikv-jemallocator = { version = "0.6", optional = true }
3742

3843
[dev-dependencies]
3944
proptest = { workspace = true }
@@ -52,3 +57,5 @@ extension-module = [
5257
ffi = ["cbindgen", "nautilus-core/ffi", "nautilus-model/ffi"]
5358
"clock_v2" = []
5459
python = ["pyo3", "nautilus-core/python", "nautilus-model/python"]
60+
allocator-jemalloc = ["tikv-jemallocator"]
61+
allocator-mimalloc = ["mimalloc"]

nautilus_core/common/src/allocator.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[cfg(all(feature = "allocator-jemalloc", feature = "allocator-mimalloc"))]
2+
compile_error!("Cannot enable both jemalloc and mimalloc allocators simultaneously");
3+
4+
#[cfg(feature = "allocator-mimalloc")]
5+
#[global_allocator]
6+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
7+
8+
#[cfg(all(
9+
feature = "allocator-jemalloc",
10+
any(target_os = "macos", target_os = "linux"),
11+
not(all(target_arch = "aarch64", target_env = "musl"))
12+
))]
13+
#[global_allocator]
14+
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
15+
16+
// Jemallocator does not work on aarch64 with musl, fallback to system allocator
17+
#[cfg(all(
18+
feature = "allocator-jemalloc",
19+
target_arch = "aarch64",
20+
target_env = "musl",
21+
))]
22+
#[global_allocator]
23+
static GLOBAL: std::alloc::System = std::alloc::System;

nautilus_core/common/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#![allow(deprecated)]
4242

4343
pub mod actor;
44+
pub mod allocator;
4445
pub mod cache;
4546
pub mod clock;
4647
pub mod component;

0 commit comments

Comments
 (0)