Repository navigation
perf(rust): the object heap in fixed chunks, and arenas that move rather than realloc - #86
Merged
Merged
Conversation
hearnadam
force-pushed
the
perf/stack-03-heap-chunks
branch
from
November 26, 2026 17:20
8144288 to
322cd2d
Compare
…her than realloc macOS does not reuse a large block that realloc grew once it is freed (20 lines of plain Rust show it), so a process running one large program after another kept every heap it ever grew: a 200k-object program peaked at 498 MB after 12 runs in one process, where QuickJS holds 78 MB. Objects now live in chunks of 4,096 slots, each allocated whole; the first starts small for the many runs that make few. Cell and string arenas past 4,096 slots move to a new allocation of twice the size instead of growing in place, and smaller ones grow by a quarter. 12 runs in one process, peak RSS: 200k objects 498 to 77 MB, JSON round-trip 84 to 14 MB, 100k closures 114 to 30 MB. Cost: heap[id] is two indexed loads, 1 to 5% more instructions on the bench programs. Array elements and Map entries are still vectors realloc grows.
kommander
force-pushed
the
perf/stack-03-heap-chunks
branch
from
November 26, 2026 22:45
322cd2d to
703d4d6
Compare
…it value_depth's margin again Inlined into every recursive conversion in debug builds, the chunked index made each level's frame larger: at depth 200 a host call's argument needed 541,567 B of a debug build's stack, past the 512 KiB (half the mobile live-run thread) that every_conversion_at_depth_200_fits_half_of_it allows. Not forced inline in debug builds, it needs 508,807 B, as before the chunks. Release builds are unchanged.
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.
macOS does not reuse a large block that realloc grew once it is freed (20 lines
of plain Rust show it), so a process running one large program after another
kept every heap it ever grew: a 200k-object program peaked at 498 MB after 12
runs in one process, where QuickJS holds 78 MB. Objects now live in chunks of
4,096 slots, each allocated whole; the first starts small for the many runs
that make few. Cell and string arenas past 4,096 slots move to a new
allocation of twice the size instead of growing in place, and smaller ones grow
by a quarter.
12 runs in one process, peak RSS: 200k objects 498 to 77 MB, JSON round-trip
84 to 14 MB, 100k closures 114 to 30 MB.
Cost: heap[id] is two indexed loads, 1 to 5% more instructions on the bench
programs. Array elements and Map entries are still vectors realloc grows.
Part 3 of 11 in a stack; based on
perf/stack-02-image. Each part was built, linted and tested on its own (cargo test --release --workspace, the same underPSYCHOSCRIPT_GC_STRESS=1, and the conformance cases underPSYCHOSCRIPT_ROUNDTRIP=1). Numbers are instructions retired, fromrust/bench/examples/corpusandmem_probe(part 1).