Skip to content

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

Merged
johnathan79717 merged 4 commits into
merge-train/barretenbergfrom
jh/heap-usage
Apr 2, 2026
Merged

feat: switch memory profiling from peak RSS to live heap usage#22266
johnathan79717 merged 4 commits into
merge-train/barretenbergfrom
jh/heap-usage

Conversation

@johnathan79717

Copy link
Copy Markdown
Contributor

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

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

AztecBot and others added 3 commits April 2, 2026 11:50
Two write() overloads in serialize.hpp used `&*buf.end()` to get a
pointer to the newly-appended region after resize(). Under
_GLIBCXX_DEBUG (enabled in asan-fast and debug presets since #22218),
dereferencing end() triggers a debug assertion abort.

Replace with `buf.data() + buf.size()` which achieves the same
pointer arithmetic without dereferencing any iterator.
## 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

- [x] Builds cleanly
- [x] Tested with deploy_ecdsar1+sponsored_fpc: heap values go up and
down as expected
- [ ] CI build passes
@johnathan79717 johnathan79717 added the ci-barretenberg Run all barretenberg/cpp checks. label Apr 2, 2026
@johnathan79717 johnathan79717 added ci-full Run all master checks. and removed ci-barretenberg Run all barretenberg/cpp checks. labels Apr 2, 2026
@johnathan79717 johnathan79717 enabled auto-merge (squash) April 2, 2026 13:04
@johnathan79717 johnathan79717 requested a review from ludamad April 2, 2026 13:07
@johnathan79717 johnathan79717 disabled auto-merge April 2, 2026 13:18
@iakovenkos iakovenkos self-requested a review April 2, 2026 13:21
@johnathan79717 johnathan79717 enabled auto-merge (squash) April 2, 2026 13:23
@johnathan79717 johnathan79717 merged commit e7adaa6 into merge-train/barretenberg Apr 2, 2026
21 checks passed
@johnathan79717 johnathan79717 deleted the jh/heap-usage branch April 2, 2026 13:44
github-merge-queue Bot pushed a commit that referenced this pull request Apr 2, 2026
BEGIN_COMMIT_OVERRIDE
fix: verify accumulated pairing points in native ChonkVerifier (#22224)
chore: enable _GLIBCXX_DEBUG in debug build presets (#22218)
feat: add --memory_profile_out flag for Chonk memory profiling (#22145)
fix: disable max capacity test in debug + tiny gate separator
improvements (#22215)
fix: WASM build for memory_profile.cpp (#22231)
fix: translator audit fixes (#22242)
fix: remove constexpr from functions using std::vector for
_GLIBCXX_DEBUG compat (#22239)
fix: pippenger edge case (#22256)
fix: avoid dereferencing past-the-end vector iterators in serialize.hpp
(#22261)
chore: crypto primitives external audit response 0 (#22263)
feat: switch memory profiling from peak RSS to live heap usage (#22266)
fix: replace UB end-iterator dereference in serialize.hpp (#22262)
fix: catch exceptions in ChonkBatchVerifier::batch_check (#22270)
END_COMMIT_OVERRIDE
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.

4 participants