feat: switch memory profiling from peak RSS to live heap usage#22266
Merged
Conversation
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
1b7df14 to
11723a8
Compare
iakovenkos
approved these changes
Apr 2, 2026
ludamad
approved these changes
Apr 2, 2026
This was referenced Apr 2, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces #22229 (which was accidentally merged into the wrong branch and reverted).
Switches
--memory_profile_outfrom 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.mallinfo2().uordblkson Linux, returns 0 on WASM, falls back to peak RSS on other platformsRssCheckpointtoMemoryCheckpoint,rss_mbtoheap_mbadd_rss_checkpointtoadd_checkpointRefs: AztecProtocol/barretenberg#1641
Example output
Test plan