From 11df47189f1443bae5ca28073e7eddf82eca580e Mon Sep 17 00:00:00 2001 From: asothii Date: Sat, 11 Oct 2025 11:49:03 +0100 Subject: [PATCH 1/5] [perf] Test mimalloc 3.1.5 --- Cargo.lock | 11 +++++++++++ compiler/rustc/Cargo.toml | 6 +++--- compiler/rustc/src/main.rs | 20 +++++++++++--------- src/librustdoc/lib.rs | 20 +++++++++++--------- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 973214a802e6e..03d6884bca1f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2152,6 +2152,16 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" +[[package]] +name = "libmimalloc-sys" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "667f4fec20f29dfc6bc7357c582d91796c169ad7e2fce709468aefeb2c099870" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libredox" version = "0.1.9" @@ -3287,6 +3297,7 @@ checksum = "e4ee29da77c5a54f42697493cd4c9b9f31b74df666a6c04dfc4fde77abe0438b" name = "rustc-main" version = "0.0.0" dependencies = [ + "libmimalloc-sys", "rustc_codegen_ssa", "rustc_driver", "rustc_driver_impl", diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml index 9ef8fa75062a2..29138ba9b6da3 100644 --- a/compiler/rustc/Cargo.toml +++ b/compiler/rustc/Cargo.toml @@ -20,10 +20,10 @@ rustc_public = { path = "../rustc_public" } rustc_public_bridge = { path = "../rustc_public_bridge" } # tidy-alphabetical-end -[dependencies.tikv-jemalloc-sys] -version = "0.6.0" +[dependencies.libmimalloc-sys] +version = "0.1.44" optional = true -features = ['unprefixed_malloc_on_supported_platforms'] +features = ["v3", "local_dynamic_tls", "arena", "extended", "override"] [features] # tidy-alphabetical-start diff --git a/compiler/rustc/src/main.rs b/compiler/rustc/src/main.rs index ca1bb59e59d60..97d5d581f3320 100644 --- a/compiler/rustc/src/main.rs +++ b/compiler/rustc/src/main.rs @@ -43,21 +43,23 @@ fn main() { { use std::os::raw::{c_int, c_void}; - use tikv_jemalloc_sys as jemalloc_sys; + use libmimalloc_sys as mimalloc_sys; #[used] - static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc; + static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = mimalloc_sys::mi_calloc; #[used] static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = - jemalloc_sys::posix_memalign; + mimalloc_sys::mi_posix_memalign; #[used] - static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc; + static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = + mimalloc_sys::mi_aligned_alloc; #[used] - static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc; + static _F4: unsafe extern "C" fn(usize) -> *mut c_void = mimalloc_sys::mi_malloc; #[used] - static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc; + static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = + mimalloc_sys::mi_realloc; #[used] - static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free; + static _F6: unsafe extern "C" fn(*mut c_void) = mimalloc_sys::mi_free; // On OSX, jemalloc doesn't directly override malloc/free, but instead // registers itself with the allocator's zone APIs in a ctor. However, @@ -66,11 +68,11 @@ fn main() { #[cfg(target_os = "macos")] { unsafe extern "C" { - fn _rjem_je_zone_register(); + fn _mi_macos_override_malloc(); } #[used] - static _F7: unsafe extern "C" fn() = _rjem_je_zone_register; + static _F7: unsafe extern "C" fn() = _mi_macos_override_malloc; } } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index d7ffb25f8bd81..badcaa2ae9e7a 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -65,7 +65,7 @@ extern crate test; // See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs // about jemalloc. #[cfg(feature = "jemalloc")] -extern crate tikv_jemalloc_sys as jemalloc_sys; +extern crate libmimalloc_sys as mimalloc_sys; use std::env::{self, VarError}; use std::io::{self, IsTerminal}; @@ -132,27 +132,29 @@ pub fn main() { use std::os::raw::{c_int, c_void}; #[used] - static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc; + static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = mimalloc_sys::mi_calloc; #[used] static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = - jemalloc_sys::posix_memalign; + mimalloc_sys::mi_posix_memalign; #[used] - static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc; + static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = + mimalloc_sys::mi_aligned_alloc; #[used] - static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc; + static _F4: unsafe extern "C" fn(usize) -> *mut c_void = mimalloc_sys::mi_malloc; #[used] - static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc; + static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = + mimalloc_sys::mi_realloc; #[used] - static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free; + static _F6: unsafe extern "C" fn(*mut c_void) = mimalloc_sys::mi_free; #[cfg(target_os = "macos")] { unsafe extern "C" { - fn _rjem_je_zone_register(); + fn _mi_macos_override_malloc(); } #[used] - static _F7: unsafe extern "C" fn() = _rjem_je_zone_register; + static _F7: unsafe extern "C" fn() = _mi_macos_override_malloc; } } From cd2fc8ee9760bd5d6a2bdb10d5897a6000e9641a Mon Sep 17 00:00:00 2001 From: asothii Date: Sat, 11 Oct 2025 11:58:55 +0100 Subject: [PATCH 2/5] Use the correct dependency for the jemalloc feature --- Cargo.lock | 8 +++++++- compiler/rustc/Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03d6884bca1f8..64668bab9894c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -908,6 +908,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + [[package]] name = "curl" version = "0.4.49" @@ -2159,6 +2165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "667f4fec20f29dfc6bc7357c582d91796c169ad7e2fce709468aefeb2c099870" dependencies = [ "cc", + "cty", "libc", ] @@ -3304,7 +3311,6 @@ dependencies = [ "rustc_public", "rustc_public_bridge", "rustc_windows_rc", - "tikv-jemalloc-sys", ] [[package]] diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml index 29138ba9b6da3..e5954541042cd 100644 --- a/compiler/rustc/Cargo.toml +++ b/compiler/rustc/Cargo.toml @@ -28,7 +28,7 @@ features = ["v3", "local_dynamic_tls", "arena", "extended", "override"] [features] # tidy-alphabetical-start check_only = ['rustc_driver_impl/check_only'] -jemalloc = ['dep:tikv-jemalloc-sys'] +jemalloc = ['dep:libmimalloc-sys'] llvm = ['rustc_driver_impl/llvm'] llvm_enzyme = ['rustc_driver_impl/llvm_enzyme'] max_level_info = ['rustc_driver_impl/max_level_info'] From 2df2a07d1281e167cd82686caac9837bf294ab3e Mon Sep 17 00:00:00 2001 From: asothii Date: Sat, 11 Oct 2025 12:10:20 +0100 Subject: [PATCH 3/5] Fix tidy --- src/tools/tidy/src/deps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 3f40bef821c9d..659da18616de8 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -482,7 +482,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "thiserror-impl", "thorin-dwp", "thread_local", - "tikv-jemalloc-sys", + "libmimalloc-sys", "tinystr", "tinyvec", "tinyvec_macros", From 6f38ef645105fb67c61593ad9129af6e32fc32a5 Mon Sep 17 00:00:00 2001 From: asothii Date: Sat, 11 Oct 2025 12:20:24 +0100 Subject: [PATCH 4/5] Change dep order for tidy --- src/tools/tidy/src/deps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 659da18616de8..86fbcf01e2b5d 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -399,6 +399,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "leb128", "libc", "libloading", + "libmimalloc-sys", "linux-raw-sys", "litemap", "lock_api", @@ -482,7 +483,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "thiserror-impl", "thorin-dwp", "thread_local", - "libmimalloc-sys", "tinystr", "tinyvec", "tinyvec_macros", From 3d5bc9210877c15b1c2794f12cd9290bf11e69e8 Mon Sep 17 00:00:00 2001 From: asothii Date: Sat, 11 Oct 2025 13:56:21 +0100 Subject: [PATCH 5/5] Add cty dep --- src/tools/tidy/src/deps.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 86fbcf01e2b5d..607b37d7b7848 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -349,6 +349,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "crossbeam-utils", "crypto-common", "ctrlc", + "cty", // Ideally removed. "darling", "darling_core", "darling_macro",