From b43b35e2e6322b6869c69b0c3d77c37f9384f59e Mon Sep 17 00:00:00 2001 From: monosans Date: Mon, 13 Jul 2026 01:59:58 +0300 Subject: [PATCH] perf: use jemalloc on macOS, use system allocator on other platforms --- .github/workflows/allocator-bench.yml | 16 ++++++++++++++++ Cargo.toml | 12 +++++------- jemallocator | 1 + mimalloc_rust | 1 + src/main.rs | 13 +++---------- 5 files changed, 26 insertions(+), 17 deletions(-) create mode 160000 jemallocator create mode 160000 mimalloc_rust diff --git a/.github/workflows/allocator-bench.yml b/.github/workflows/allocator-bench.yml index 1d3ff1b..57762e6 100644 --- a/.github/workflows/allocator-bench.yml +++ b/.github/workflows/allocator-bench.yml @@ -60,6 +60,22 @@ jobs: allocator: jemalloc - platform: windows-11-arm allocator: jemalloc + - platform: windows-2025 + allocator: mimalloc_v2_no_thp + - platform: windows-2025 + allocator: mimalloc_v3_no_thp + - platform: windows-11-arm + allocator: mimalloc_v2_no_thp + - platform: windows-11-arm + allocator: mimalloc_v3_no_thp + - platform: macos-26 + allocator: mimalloc_v2_no_thp + - platform: macos-26 + allocator: mimalloc_v3_no_thp + - platform: macos-26-intel + allocator: mimalloc_v2_no_thp + - platform: macos-26-intel + allocator: mimalloc_v3_no_thp steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: diff --git a/Cargo.toml b/Cargo.toml index eb7e548..3c9b59e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ smallvec = { version = "=1.15.2", features = [ "union", ], optional = true } strum = { version = "=0.28.0", features = ["derive"], optional = true } -tikv-jemallocator = { version = "=0.7.0", features = [ +tikv-jemallocator = { version = "=0.7.0", default-features = false, features = [ "override_allocator_on_supported_platforms", ], optional = true } tokio = { version = "=1.52.3", features = ["fs", "parking_lot", "signal"] } @@ -80,17 +80,15 @@ tui-logger = { version = "=0.18.3", features = [ ], optional = true } url = "=2.5.8" -[target.'cfg(all(any(target_arch = "aarch64", target_arch = "x86_64"), any(all(target_os = "linux", any(target_env = "musl", target_env = "gnu")), target_os = "macos", all(target_os = "windows", target_env = "msvc"))))'.dependencies] -mimalloc-auto = { package = "mimalloc", version = "=0.1.52", features = [ - "no_thp", - "override", - "v2" +[target.'cfg(target_os = "macos")'.dependencies] +tikv-jemallocator-auto = { package = "tikv-jemallocator", version = "=0.7.0", default-features = false, features = [ + "override_allocator_on_supported_platforms", ], optional = true } [features] default = ["auto-allocator"] __mimalloc = ["dep:mimalloc"] -auto-allocator = ["dep:mimalloc-auto"] +auto-allocator = ["dep:tikv-jemallocator-auto"] dhat = ["dep:dhat"] jemalloc = ["dep:tikv-jemallocator"] mimalloc_v2 = ["__mimalloc", "mimalloc/v2"] diff --git a/jemallocator b/jemallocator new file mode 160000 index 0000000..0e91291 --- /dev/null +++ b/jemallocator @@ -0,0 +1 @@ +Subproject commit 0e9129157d261cf6bda86d5dcd9eba94f3cd0f96 diff --git a/mimalloc_rust b/mimalloc_rust new file mode 160000 index 0000000..a35cc75 --- /dev/null +++ b/mimalloc_rust @@ -0,0 +1 @@ +Subproject commit a35cc759c071fd7bd586685048367839002b95dd diff --git a/src/main.rs b/src/main.rs index 20d04c4..b864a9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,17 +69,10 @@ use tracing_subscriber::{ layer::SubscriberExt as _, util::SubscriberInitExt as _, }; -#[cfg(all( - feature = "auto-allocator", - any(target_arch = "aarch64", target_arch = "x86_64"), - any( - all(target_os = "linux", any(target_env = "musl", target_env = "gnu")), - target_os = "macos", - all(target_os = "windows", target_env = "msvc") - ), -))] +#[cfg(all(feature = "auto-allocator", target_os = "macos"))] #[global_allocator] -static GLOBAL: mimalloc_auto::MiMalloc = mimalloc_auto::MiMalloc; +static GLOBAL: tikv_jemallocator_auto::Jemalloc = + tikv_jemallocator_auto::Jemalloc; #[cfg(feature = "dhat")] #[global_allocator]