Repository navigation
perf(cli): mimalloc global allocator for the rledger binary (-7% load) - #1599
Conversation
Post-green-conversion, the cachegrind breakdown shows allocator machinery is the #1 cost (~14%) of the load — the pipeline makes many small short-lived allocations that glibc malloc handles poorly. Set mimalloc as the rledger binary's global allocator: -7.0% instructions on the 10k-txn workload (likely more wall-clock), process-wide so every command benefits. Binary-only (never the library — embedders choose their own allocator), gated off wasm (C lib), default-on via a new mimalloc feature (opt out with --no-default-features). Pure-Rust allocators evaluated + rejected (ferroc won't compile on the toolchain; talc v5 is embedded-oriented). rledger check smoke test: identical output.
📊 Benchmark Results
vs main branch (2026-06-25)
What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR introduces an optional mimalloc global allocator for the rledger CLI binary to reduce allocator overhead during the load → process pipeline.
Changes:
- Add
#[global_allocator]usingmimalloc::MiMallocin therledgerbinary behindcfg(feature = "mimalloc")andnot(wasm32). - Add a new
mimallocCargo feature and dependency, and enable it viadefaultfeatures. - Update
Cargo.lockfor the new allocator dependency chain (mimalloc/libmimalloc-sys).
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger/src/bin/rledger.rs | Installs mimalloc as the global allocator for the rledger binary under a feature + non-wasm cfg gate. |
| crates/rustledger/Cargo.toml | Adds the mimalloc feature/dependency and enables it by default. |
| Cargo.lock | Records the new allocator dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…umers Review fix (Copilot): mimalloc was in the rustledger crate default features, but the crate has a [lib] target published to crates.io — default features apply to library consumers, forcing a vendored C dependency (+ C toolchain) on every embedder. Move it out of default to an opt-in mimalloc feature; the binary global allocator is still gated on it (+ not wasm). Release binaries enable it explicitly (follow-up wires --features mimalloc into release-build.yml).
|
Good catch — fixed in 7083694. Moved |
…1601) * ci(release): enable mimalloc in release rledger binaries (-7% load) Follow-up to #1599 (mimalloc opt-in feature) + #1600. The release builds use --no-default-features, so the opt-in feature wasn't reaching shipped binaries. Add --features mimalloc to the rledger builds (PGO Unix/Windows + native non-cross) so released binaries get the ~7% lower-load allocator win. Cross-compiled targets are intentionally excluded: mimalloc's vendored C build isn't validated under cross here, and a release shouldn't hinge on it — they ship without the allocator. Feature resolution verified locally (cargo build --no-default-features --features mimalloc resolves at the virtual workspace root); rledger output is unchanged (allocator-only). * ci(release): clarify mimalloc cross-vs-native comments (review)
What
Set
mimallocas the global allocator for therledgerbinary.Why
After the green-conversion campaign (#1594/#1595/#1596/#1598) cut the parser ~30%, a fresh cachegrind breakdown showed the allocator machinery is now the #1 cost (~14%) of the load —
_int_malloc/free/malloc_consolidate/ … The load → process pipeline makes thousands of small, short-lived allocations (green-tree build + AST conversion + booking); glibc malloc is a poor fit for that pattern.Result
Measured on the 10k-txn workload (cachegrind, same harness, only the allocator differs):
cachegrind counts instructions; mimalloc's wall-clock win is typically larger (thread-local heaps, cache locality, less fragmentation). And it's process-wide — every command (check / query / format) benefits, not just parse.
Design
#[global_allocator]lives insrc/bin/rledger.rs, never the library — embedders pick their own allocator.cfg(not(target_arch = "wasm32"))(mimalloc is a C lib).mimallocfeature;--no-default-featuresdrops it (e.g. a build host without a C toolchain).Tradeoff
Adds
libmimalloc-sys(a vendored C library) — build time, binary size, and a non-Rust dep forcargo deny. Pure-Rust allocators were evaluated and rejected:ferrocdoesn't compile on rustc 1.96 (let-chains/edition) across all published versions, andtalcv5 is an embedded/wasm-oriented rewrite with no std-heap drop-in. The root-cause pure-Rust fix (arena-allocating the conversion) is a larger follow-up.Verification
rledger checkon the workload:✓ No errors found— output identical (allocator swap, no logic change).🤖 Generated with Claude Code