From 2c7670bef9abc472b15b7166e4a5587647c35a4c Mon Sep 17 00:00:00 2001 From: not-matthias Date: Fri, 9 Oct 2026 18:28:28 +0200 Subject: [PATCH 1/2] perf: use mimalloc as the runner's global allocator The release binary targets musl, whose allocator is slow on many small allocations and serializes threads. Post-processing a memory run decodes the whole memtrack artifact with one or more allocations per event, which on a 62M-event artifact took 8-19 minutes in CI with the musl build against 1-2 minutes with glibc for the same code. Use mimalloc, as memtrack already does, so the runner no longer depends on the libc allocator. --- Cargo.lock | 1 + Cargo.toml | 2 ++ crates/memtrack/Cargo.toml | 2 +- src/main.rs | 4 ++++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d7bdaa3cd..f0f9e20ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -730,6 +730,7 @@ dependencies = [ "log", "memmap2", "memtrack", + "mimalloc", "nestify", "nix 0.31.3", "object", diff --git a/Cargo.toml b/Cargo.toml index f85f895d3..c8df261fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,7 @@ linux-perf-data = { git = "https://github.com/mstange/linux-perf-data.git", rev ] } # unreleased main as of 2026-03-19 debugid = "0.8.0" memmap2 = "0.9.10" +mimalloc = { workspace = true } nix = { version = "0.31.3", features = ["fs", "time", "user"] } futures = "0.3.32" runner-shared = { path = "crates/runner-shared" } @@ -113,6 +114,7 @@ libc = "0.2" log = "0.4.28" serde_json = "1.0" serde = { version = "1.0.228", features = ["derive"] } +mimalloc = "0.1" ipc-channel = "0.20" itertools = "0.14.0" rayon = "1.12" diff --git a/crates/memtrack/Cargo.toml b/crates/memtrack/Cargo.toml index 20bf77fee..6e9279b1f 100644 --- a/crates/memtrack/Cargo.toml +++ b/crates/memtrack/Cargo.toml @@ -40,7 +40,7 @@ byteorder = "1.5" rayon = "1.12" parking_lot = "0.12" typed-builder = "0.23.2" -mimalloc = { version = "0.1", optional = true } +mimalloc = { workspace = true, optional = true } [build-dependencies] libbpf-cargo = { version = "0.26", optional = true } diff --git a/src/main.rs b/src/main.rs index 518b8d3ef..446d01bb6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ +// musl's allocator is slow on the many small allocations made when decoding memtrack artifacts. +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + use codspeed_runner::{clean_logger, cli}; use console::style; use log::log_enabled; From 5ee7e5883fe6b2929a32a4960ed9e9392ea00538 Mon Sep 17 00:00:00 2001 From: not-matthias Date: Mon, 12 Oct 2026 18:18:24 +0200 Subject: [PATCH 2/2] test(runner-shared): run the memtrack benches on mimalloc --- Cargo.lock | 1 + crates/runner-shared/Cargo.toml | 1 + crates/runner-shared/benches/memtrack_reader.rs | 3 +++ crates/runner-shared/benches/memtrack_writer.rs | 3 ++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index f0f9e20ca..c44350fe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3661,6 +3661,7 @@ dependencies = [ "linux-perf-event-reader 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "log", "memmap2", + "mimalloc", "rand 0.8.6", "rayon", "rmp", diff --git a/crates/runner-shared/Cargo.toml b/crates/runner-shared/Cargo.toml index 594d9cab8..83d3d16ab 100644 --- a/crates/runner-shared/Cargo.toml +++ b/crates/runner-shared/Cargo.toml @@ -28,6 +28,7 @@ zstd = "0.13.3" [dev-dependencies] divan = { version = "4.2.0", package = "codspeed-divan-compat" } memmap2 = "0.9.10" +mimalloc = { workspace = true } rand = "0.8" tempfile = { workspace = true } diff --git a/crates/runner-shared/benches/memtrack_reader.rs b/crates/runner-shared/benches/memtrack_reader.rs index 2215eb643..87a1d0e6e 100644 --- a/crates/runner-shared/benches/memtrack_reader.rs +++ b/crates/runner-shared/benches/memtrack_reader.rs @@ -15,6 +15,9 @@ use runner_shared::measurement_mode::MeasurementMode; use runner_shared::runtime_env::RUNNER_MODE_ENV; use std::io::Write; +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + fn main() { divan::main(); } diff --git a/crates/runner-shared/benches/memtrack_writer.rs b/crates/runner-shared/benches/memtrack_writer.rs index 580424a1a..2e5eec1fc 100644 --- a/crates/runner-shared/benches/memtrack_writer.rs +++ b/crates/runner-shared/benches/memtrack_writer.rs @@ -16,7 +16,8 @@ use runner_shared::artifacts::{ /// there anyway. #[cfg(not(codspeed))] #[global_allocator] -static ALLOC: divan::AllocProfiler = divan::AllocProfiler::system(); +static ALLOC: divan::AllocProfiler = + divan::AllocProfiler::new(mimalloc::MiMalloc); fn main() { divan::main();