Skip to content

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

Description

@polaz

Context

compare_ffi_memory.rs reports total bytes allocated by Rust vs FFI per scenario but doesn't attribute allocations to call sites.

Resolution

Implemented as the dhat-heap cargo feature (default off) wired into the standalone profiling examples instead of the criterion harness:

  • zstd/Cargo.toml: optional dhat = "0.3" dep behind dhat-heap feature
  • zstd/examples/encode_loop_reuse_z000033.rs, zstd/examples/encode_loop_dict.rs: global allocator + profiler blocks; write dhat-heap.json with per-call-site blocks/bytes (totals, t-gmax, t-end)

The standalone-example shape beats the original compare_ffi_memory.rs plan: the criterion harness pollutes attribution with setup/training/validation allocations, while the examples isolate the steady-state loop. Allocation COUNTS are platform-independent, so runs on any host diagnose musl-amplified churn.

Proven in practice: attributed the 13 allocs/frame on the reused-compressor dict path (row-table oscillation / estimator boxes / huffman seed clone / header temporaries) and the BT dms per-frame rebuild — both eliminated (musl 5.5× win).

The donor-proxy delta column (vs ZSTD_sizeof_CCtx) was not built; compare_ffi_memory.rs totals already give the cross-side comparison, dhat gives the our-side breakdown.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumMedium priority — important improvementenhancementNew feature or requestperformancePerformance optimization

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions