From d4aec6ca5cb3a6753443d0d0eed6ebded5f91152 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 21 Nov 2026 14:54:10 +0000 Subject: [PATCH] fix: Use mimalloc for c/c++ code by default --- src/core/Cargo.toml | 4 ++++ src/core/alloc/mod.rs | 2 ++ src/core/config/check.rs | 7 ------- src/main/Cargo.toml | 4 ---- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index b4aa779a8..48a0f2e9e 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -31,9 +31,13 @@ jemalloc = [ "dep:tikv-jemalloc-ctl", "dep:tikv-jemallocator", ] +# Uses mimalloc for Rust allocations and, via `override`, exports +# malloc/free/etc. so C/C++ dependencies (RocksDB, zstd, lz4, ...) use it too. +# Mutually exclusive with `jemalloc` on non-MSVC targets. mimalloc = [ "dep:libmimalloc-sys", "dep:mimalloc", + "libmimalloc-sys/override", ] jemalloc_conf = [] jemalloc_prof = [ diff --git a/src/core/alloc/mod.rs b/src/core/alloc/mod.rs index 3acfb43a0..c7e8dd49d 100644 --- a/src/core/alloc/mod.rs +++ b/src/core/alloc/mod.rs @@ -9,6 +9,8 @@ pub(crate) use je::metric; pub use je::{memory_stats, memory_usage, memory_usage_stats, trim}; // mimalloc +#[cfg(all(feature = "mimalloc", feature = "jemalloc", not(target_env = "msvc")))] +compile_error!("the `mimalloc` and `jemalloc` features are mutually exclusive"); #[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))] pub mod mimalloc; #[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))] diff --git a/src/core/config/check.rs b/src/core/config/check.rs index 70a403d06..146e149e7 100644 --- a/src/core/config/check.rs +++ b/src/core/config/check.rs @@ -43,13 +43,6 @@ pub fn check(config: &Config) -> Result { )); } - if cfg!(all(feature = "mimalloc", feature = "jemalloc", not(target_env = "msvc"))) { - warn!( - "mimalloc and jemalloc compile-time features are both enabled, this causes jemalloc \ - to be used." - ); - } - if cfg!(not(unix)) && config.unix_socket_path.is_some() { return Err!(Config( "unix_socket_path", diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 6c403f3b6..c4477721f 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -112,10 +112,6 @@ jemalloc = [ "conduwuit-core/jemalloc", "conduwuit-service/jemalloc", ] -# Sets Rust's #[global_allocator] to mimalloc (C/C++ libraries such as RocksDB -# still use system libc malloc). On non-MSVC targets, `jemalloc` takes -# precedence if both are enabled, so build with `--no-default-features` and -# omit `jemalloc`/`standard` to use mimalloc. mimalloc = [ "conduwuit-core/mimalloc", ]