From 451817d3f65f1473fbdd8c4aa4dff72c670e0b05 Mon Sep 17 00:00:00 2001 From: Almaz Date: Sat, 9 May 2026 03:41:10 +0300 Subject: [PATCH] feat: use mimalloc v2 as default allocator --- Cargo.toml | 11 +++++++++-- src/main.rs | 21 +++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cb6d61c..62ca0ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,10 +79,17 @@ tui-logger = { version = "=0.18.2", 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.50", features = [ + "no_thp", + "override", + "v2" +], optional = true } + [features] -# default = ["auto-allocator"] +default = ["auto-allocator"] __mimalloc = ["dep:mimalloc"] -auto-allocator = ["dep:mimalloc"] +auto-allocator = ["dep:mimalloc-auto"] dhat = ["dep:dhat"] jemalloc = ["dep:tikv-jemallocator"] mimalloc_v2 = ["__mimalloc", "mimalloc/v2"] diff --git a/src/main.rs b/src/main.rs index ce354a1..ab92922 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,6 +69,18 @@ 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") + ), +))] +#[global_allocator] +static GLOBAL: mimalloc_auto::MiMalloc = mimalloc_auto::MiMalloc; + #[cfg(feature = "dhat")] #[global_allocator] static GLOBAL: dhat::Alloc = dhat::Alloc; @@ -77,14 +89,7 @@ static GLOBAL: dhat::Alloc = dhat::Alloc; #[global_allocator] static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; -#[cfg(any( - all( - feature = "auto-allocator", - any(target_arch = "aarch64", target_arch = "x86_64"), - any(target_os = "linux", target_os = "macos", target_os = "windows"), - ), - feature = "__mimalloc" -))] +#[cfg(feature = "__mimalloc")] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;