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
Context
Current
compare_ffi_memory.rsreports total bytes allocated by Rust vsFFI 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:frame_compressor.rs:142 (Vec::with_capacity)Acceptance criteria
dhatintegration that captures call stacksZSTD_estimateCCtxSize / direct ZSTD_sizeof_CCtx if accessible)
compare_ffi_memory.rshow to enable / interpret outputPriority
Low — tooling for future memory regressions. Pull when the next memory
gap surfaces; don't pull preemptively.
Files involved
dhator custom allocator)References
zstd-cli/src/compare_ffi_memory.rs