mod-alloc 0.9.0

Allocation profiling for Rust. Counters, peak resident, and call-site grouping with inline backtrace capture. Zero external dependencies in the hot path. Lean dhat replacement targeting MSRV 1.75.
Documentation
  • Coverage
  • 100%
    15 out of 15 items documented9 out of 9 items with examples
  • Size
  • Source code size: 59.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 487.79 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 33s Average build duration of successful builds.
  • all releases: 28s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • jamesgober/mod-alloc
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jamesgober

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 backtraces feature)

Designed as a lean replacement for dhat with:

  • MSRV 1.75 (vs dhat's 1.85+)
  • Zero external dependencies in the hot path (no backtrace crate)
  • Lower overhead per allocation via purpose-built inline capture
  • DHAT-compatible output so existing viewer tools work (via the dhat-compat feature)

Quick start

use mod_alloc::{Profiler, ModAlloc};

#[global_allocator]
static GLOBAL: ModAlloc = ModAlloc::new();

fn main() {
    let p = Profiler::start();

    let v: Vec<u64> = (0..1000).collect();
    drop(v);

    let stats = p.stop();
    println!("Allocations: {}", stats.alloc_count);
    println!("Total bytes: {}", stats.total_bytes);
    println!("Peak bytes:  {}", stats.peak_bytes);
}

Feature flags

[dependencies]
mod-alloc = "0.9"                                                      # counters only (default)
mod-alloc = { version = "0.9", features = ["backtraces"] }             # + call-site capture (lands in v0.9.1)
mod-alloc = { version = "0.9", features = ["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.