Skip to content

tooling: per-alloc-site memory tracker in compare_ffi_memory.rs #211

@polaz

Description

@polaz

Context

Current compare_ffi_memory.rs reports total bytes allocated by Rust vs
FFI on each scenario but doesn't attribute allocations to specific call
sites. When the Rust path uses 1.4× more memory than donor we can't tell
which struct/buffer is responsible without instrumenting by hand.

Goal

Per-alloc-site attribution: track allocations through a custom global
allocator (or dhat-style sampling) so the report shows:

Site (file:line) Bytes (Rust) Bytes (FFI proxy) Δ
frame_compressor.rs:142 (Vec::with_capacity) 8 MB 4 MB +4 MB
... ... ... ...

Acceptance criteria

  • Allocator wrapper or dhat integration that captures call stacks
  • Report sorted by abs delta vs donor proxy (donor bytes inferred from
    ZSTD_estimateCCtxSize / direct ZSTD_sizeof_CCtx if accessible)
  • Gated under a cargo feature (default off — adds overhead)
  • Documented in compare_ffi_memory.rs how to enable / interpret output

Priority

Low — tooling for future memory regressions. Pull when the next memory
gap surfaces; don't pull preemptively.

Files involved

  • zstd-cli/src/compare_ffi_memory.rs (existing harness)
  • zstd-cli/Cargo.toml (new optional dep: dhat or custom allocator)

References

  • Existing harness: zstd-cli/src/compare_ffi_memory.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumMedium priority — important improvementenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions