Skip to content

feat: switch memory profiling from peak RSS to live heap usage#22229

Merged
johnathan79717 merged 1 commit into
claudebox/fix-merge-train-bb-constexprfrom
jh/heap-usage
Apr 2, 2026
Merged

feat: switch memory profiling from peak RSS to live heap usage#22229
johnathan79717 merged 1 commit into
claudebox/fix-merge-train-bb-constexprfrom
jh/heap-usage

Conversation

@johnathan79717

Copy link
Copy Markdown
Contributor

Summary

Switches --memory_profile_out from peak RSS (getrusage, monotonically increasing) to live heap usage (mallinfo2, goes up and down). This matches what Tracy's memory view showed and reveals when memory is actually freed.

  • Uses mallinfo2().uordblks on Linux (falls back to peak RSS on other platforms)
  • Renamed RssCheckpoint to MemoryCheckpoint, rss_mb to heap_mb
  • Removes duplicate getrusage implementation, reuses peak_rss_bytes() from logstr for fallback

Now shows patterns like: alloc 202 MiB -> oink frees to 157 MiB, revealing that commitment batching reclaims ~45 MiB.

Refs: AztecProtocol/barretenberg#1641

Example output

 0 MultiCallEntrypoint:entrypoint  after_alloc     76 MiB
 0 MultiCallEntrypoint:entrypoint  after_trace     76 MiB
 0 MultiCallEntrypoint:entrypoint  after_oink      60 MiB  <-- freed during commitments
 ...
 6 EcdsaRAccount:entrypoint        after_alloc    195 MiB
 6 EcdsaRAccount:entrypoint        after_trace    202 MiB  <-- peak
 6 EcdsaRAccount:entrypoint        after_oink     157 MiB  <-- 45 MiB freed
 ...
 8 SponsoredFPC:sponsor            after_alloc     42 MiB  <-- small circuit

Test plan

  • Builds cleanly
  • Tested with deploy_ecdsar1+sponsored_fpc: heap values go up and down as expected
  • CI build passes

@johnathan79717 johnathan79717 added ci-barretenberg Run all barretenberg/cpp checks. ci-full Run all master checks. and removed ci-barretenberg Run all barretenberg/cpp checks. labels Apr 1, 2026
@johnathan79717 johnathan79717 requested a review from ludamad April 1, 2026 16:23
@johnathan79717 johnathan79717 enabled auto-merge (squash) April 2, 2026 11:34
Peak RSS is a monotonically increasing high-water mark that includes
freed-but-not-returned pages, making it hard to see when memory is
actually freed. Live heap usage via mallinfo2() tracks what's currently
allocated by malloc, going up and down as memory is allocated and freed.
This matches what Tracy's memory view showed.

Now we can see patterns like: alloc 202 MiB -> oink frees to 157 MiB,
revealing that commitment batching reclaims ~45 MiB of polynomial memory.

Renamed RssCheckpoint to MemoryCheckpoint, rss_mb to heap_mb,
add_rss_checkpoint to add_checkpoint.
@johnathan79717 johnathan79717 changed the base branch from merge-train/barretenberg to claudebox/fix-merge-train-bb-constexpr April 2, 2026 12:52
@johnathan79717 johnathan79717 merged commit e22f2cd into claudebox/fix-merge-train-bb-constexpr Apr 2, 2026
7 of 8 checks passed
@johnathan79717 johnathan79717 deleted the jh/heap-usage branch April 2, 2026 12:52
johnathan79717 added a commit that referenced this pull request Apr 2, 2026
johnathan79717 added a commit that referenced this pull request Apr 2, 2026
johnathan79717 added a commit that referenced this pull request Apr 2, 2026
@iakovenkos iakovenkos requested review from iakovenkos and removed request for iakovenkos April 2, 2026 13:20
johnathan79717 added a commit that referenced this pull request Apr 2, 2026
## Summary

Replaces #22229 (which was accidentally merged into the wrong branch and
reverted).

Switches `--memory_profile_out` from peak RSS (getrusage, monotonically
increasing) to live heap usage (mallinfo2, goes up and down). This
matches what Tracy's memory view showed and reveals when memory is
actually freed.

- Uses `mallinfo2().uordblks` on Linux, returns 0 on WASM, falls back to
peak RSS on other platforms
- Renamed `RssCheckpoint` to `MemoryCheckpoint`, `rss_mb` to `heap_mb`
- Renamed `add_rss_checkpoint` to `add_checkpoint`

Refs: AztecProtocol/barretenberg#1641

## Example output

```
 0 MultiCallEntrypoint:entrypoint  after_alloc     76 MiB
 0 MultiCallEntrypoint:entrypoint  after_oink      60 MiB  <-- freed during commitments
 6 EcdsaRAccount:entrypoint        after_trace    202 MiB  <-- peak
 6 EcdsaRAccount:entrypoint        after_oink     157 MiB  <-- 45 MiB freed
 8 SponsoredFPC:sponsor            after_alloc     42 MiB  <-- small circuit
```

## Test plan

- [x] Builds cleanly (native + asan-fast locally)
- [x] Tested with deploy_ecdsar1+sponsored_fpc: heap values go up and
down as expected
- [ ] CI build passes

---------

Co-authored-by: AztecBot <tech@aztec-labs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-full Run all master checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants