What it does
mod-alloc is a global-allocator wrapper that tracks every
allocation and deallocation. It answers:
- How many allocations did this code path make?
- How many total bytes were allocated?
- What was the peak resident memory?
- Which call-sites caused the most allocations? (with
backtracesfeature)
Designed as a lean replacement for dhat with:
- MSRV 1.75 (vs dhat's 1.85+)
- Zero external dependencies in the hot path (no
backtracecrate) - Lower overhead per allocation via purpose-built inline capture
- DHAT-compatible output so existing viewer tools work (via the
dhat-compatfeature)
Quick start
use ;
static GLOBAL: ModAlloc = new;
Feature flags
[]
= "0.9" # counters only (default)
= { = "0.9", = ["backtraces"] } # + call-site capture (lands in v0.9.1)
= { = "0.9", = ["dhat-compat"] } # + DHAT-format output (lands in v0.9.3)
Why a new allocation profiler
dhat is the de-facto standard but its dependency chain
(backtrace 0.3.76 → addr2line 0.25.1) locks consumers at Rust
1.85. For projects with broader MSRV targets, this is a real cost.
mod-alloc provides the same core capability with inline backtrace
capture (frame-pointer-based, x86_64 + aarch64 initially) and no
external dependencies. The trade: fewer architectures supported in
v1.0; we add ARM32, RISC-V, etc. based on demand.
Status
v0.9.0 ships Tier 1 (counters). Installing ModAlloc as
#[global_allocator] tracks every allocation, deallocation,
reallocation, and zero-init allocation against four lock-free
atomic counters. Per-allocation overhead measures under 50 ns on
x86_64 (cargo run --release --example bench_overhead). Tier 2
(inline backtrace capture) lands in v0.9.1. Tier 3
(DHAT-compatible JSON output) lands in v0.9.3. The 1.0 release
freezes the public API and the wire format.
Minimum supported Rust version
1.75, pinned in Cargo.toml and verified by CI.
License
Apache-2.0. See LICENSE.