Skip to content

#2407: the debug allocator reports the peak live memory and its shape - #3070

Merged
ehartford merged 1 commit into
mainfrom
debug-alloc-peak
Nov 7, 2026
Merged

ehartford merged 1 commit into
mainfrom
debug-alloc-peak

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

#2407: the debug allocator reports the peak live memory and its shape, beside its leak report.

debug-alloc: peak live bytes=749513264 blocks=2381030 at allocation=484538224
debug-alloc: peak by origin: with_alloc=12718736 List=393296832 HashMap=279532256 str=63745936 fmt=217856 unknown=1648
debug-alloc: peak by size (bytes>=: blocks): 16:496814 32:874509 64:426792 128:386581 256:92129 … 33554432:1
debug-alloc: largest requests (bytes origin): 41287680 List 20643840 List 10321920 List 8388608 List 5852864 str …

That is the compiler checking src/main.w (stage2 of this branch, WITH_DEBUG_ALLOC=1): 750 MB of live payload at the peak in 2.4 M blocks — List buffers 393 MB, HashMap tables 280 MB, strings 64 MB; 1.4 M of the live blocks are 64 bytes or smaller; the largest single buffer is a 41 MB List. The OS's max RSS for the same check is 773 MB, so the payload is the footprint; the 1.5 GB the issue measured is the stage compile, whose report is the next run.

How. The ledger already held each block's size and origin; dbg_account_alloc / dbg_account_free keep live bytes and blocks, the per-origin split and a log2 histogram, and snapshot them at every new peak with the request ordinal; the eight largest distinct request sizes are kept with their owners. The runtime's own owners are tagged at their rt_alloc sites (HashMap, SlotMap, str for NUL-terminated buffers, fmt), so the split names the table a block belongs to; the site of any block stays the address trap's (WITH_DEBUG_ALLOC_TRAP_FREE under lldb).

Explicit exits. std.process.exit_code, std.compiler.exit and the compiler's own main go through with_exit, which prints the peak report and not the leak walk: what is still allocated when a program chooses to stop is not a leak. The compiler's main had called libc's exit through std.libc, so no report of any kind ever printed for the compiler itself (a tool that stayed silent).

Fixture test/debug_alloc/da_2407_peak_report.w; debug-allocator.md gains the report's section.

Beside the leak report: peak live bytes and blocks and the allocation that
reached them, the peak split by origin kind, a log2 histogram of the blocks
live at the peak, and the largest requests of the run. The runtime's own
owners are tagged (HashMap, SlotMap, str, fmt) so the split names the
table a block belongs to. An explicit exit (std.process.exit_code,
std.compiler.exit, the compiler's own main) goes through with_exit, which
prints the peak report without the leak walk: what is still allocated at
an explicit exit is not a leak. Measured on the compiler checking
src/main.w: 750 MB live payload at the peak in 2.4M blocks — List 393 MB,
HashMap 280 MB, str 64 MB; 1.4M live blocks of 64 bytes or less; the
largest single buffer a 41 MB List.
@ehartford
ehartford marked this pull request as ready for review November 7, 2026 19:14
@ehartford
ehartford merged commit 6f20fe4 into main Nov 7, 2026
@ehartford
ehartford deleted the debug-alloc-peak branch November 7, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant