Skip to content

Shorten the generational allocation fast path - #22

Open
Qard wants to merge 5 commits into
perf/collect-capacityfrom
perf/alloc-start-bitmap
Open

Qard wants to merge 5 commits into
perf/collect-capacityfrom
perf/alloc-start-bitmap

Conversation

@Qard

@Qard Qard commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #21; the base is perf/collect-capacity. It shortens the generational inline allocation fast path. Report: docs/results/alloc-fast-path-v1.md.

Changes

No object-start bits for the nursery (4b9ecaca8):

  • What read them. Only two things read the young start bits: a major collection that compacts a non-empty nursery whose survivors cannot fit the old prefix, and the heap tools.
  • Walking by extents instead. The nursery is bump-allocated without gaps, so both now walk it by object extents. The compactor's fallback records the nursery's starts first with recordObjectStarts, which throws if the walk does not end exactly at the young top.
  • Fast path. Neither backend's generational fast path sets a start bit any more, and minors no longer clear them. The copying runtime keeps its bits.
  • Heap tools. Descriptor version 3, in tint_heap.py, the snapshot graph and verify-heap-tools.
  • New test. tools/native-gc-nursery-fallback.test.ts forces the fallback compaction with serial marking (4 MiB) and with pool marking (32 MiB).

Precomputed nursery address (612a13cc0):

  • The runtime writes the nursery's absolute address into state words 16/17 before publication.
  • Both backends form the object address with one load and one add.
  • Publication on both backends rejects a state block shorter than 18 words.
  • The copying runtime's emitted bytes are unchanged.

Fast path, instructions from the context load to the object address

Step arm64 x86-64
Before 23 27
Without start bits 14 18
With the nursery address 12 17

Results (macOS arm64)

Frozen v7 (15 paired rounds, order alternating), against #21:

  • cycles 1.0015 (quartiles 0.987–1.026), neutral;
  • instructions 0.9950, lower in all 15 rounds;
  • RSS unchanged.

Allocating kernels, cycles against #21 (15 rotated rounds):

Kernel Cycles
serialization −3.5%
collections −3.2%
strings −1.7%
closures −1.1%
records −0.3%
pipelines +0.5%

Records and pipelines are within their quartiles. Peak RSS is 1.0–1.7% lower in every kernel.

Absolute cursor and limit: assessed, not built

Option arm64 x86-64
Absolute cursor in state 9 15
Cursor in hosted context 7 14
  • Not built. The precomputed address saved two instructions and moved the kernels by under 1%. An absolute cursor would save three more, smaller still, and it touches the runtime, both backends' publication, the arm64 diagnostics and the heap-tools format.
  • x86-64 parity. x86-64 computes the large-object threshold, max(128, young capacity / 4), on every allocation (8 instructions); arm64 has no threshold. This is recorded for a separate, measured decision.

Gates

  • Unit tests: codegen, native-runtime and build capabilities, 691/691.
  • Collector native fixtures: 18/18 under LLDB, including the nursery fallback.
  • verify-heap-tools: passes.
  • Self-build: subset check passes; stage2 == stage3.
  • CI: all three platforms green on 612a13cc0 (dispatch run 45296580121), whose tree matches this head apart from the merges and docs.

🤖 Generated with Claude Code


Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Qard and others added 5 commits November 24, 2026 08:13
Every inline allocation set the object's start bit, about nine instructions
plus a dependent read-modify-write of the bitmap word, and every minor
collection cleared the nursery's bits again. Only two things read those bits:
- a major collection that compacts a non-empty nursery;
- the heap tools.
The nursery is bump-allocated without gaps, so both can walk it by object
extents instead.

- Allocation: the generational fast path on both backends and the
  allocator's slow path no longer set nursery start bits. The copying
  runtime keeps them. Old-space bits are unchanged (evacuation, direct-old
  allocation, compaction).
- Collections: minors no longer clear any nursery bits. A compaction that
  covers the nursery (its survivors could not fit the old prefix) first
  records the nursery's object starts by walking it (recordObjectStarts).
  Compaction clears every start bit it passes, so they are zero again
  afterwards.
- Heap tools: descriptor version 3. The old prefix is walked through its
  start bits and the nursery by extents, in tint_heap.py and in the
  snapshot graph. verify-heap-tools checks that the nursery's extents chain
  from its base exactly to its top.

tools/native-gc-nursery-fallback.test.ts forces that compaction with serial
marking (4 MiB heap) and pool marking (32 MiB): a nursery full of survivors
that the old prefix cannot hold. LLDB counted 5 compactions through the
nursery walk in each, and both checksums match Node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The generational fast path formed each object's address from the young base
offset (state word 2 or 7), the managed base read through the context, and
the young top: two loads and two adds on arm64, one load and two adds on
x86-64. The runtime now writes the nursery's absolute address (managed base
plus old-prefix capacity) into state words 16/17 before publication, and both
backends load it once and add the young top.

- ABI: nativeGenerationalNurseryAddressOffset (64) and
  nativeGenerationalStateWords (18). Publication on both backends rejects a
  state block shorter than eighteen words, so the fast path never reads past
  it.
- The copying runtime keeps its semispace-relative sequence unchanged, byte
  for byte.
- allocation-throughput.md documents the eighteen-word block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without nursery start bits and with the precomputed nursery address, the
arm64 generational fast path is 12 instructions instead of 23, and x86-64's
is 17 instead of 27. The allocating kernels drop 1-3.5% of cycles and
1-1.7% of peak RSS. Frozen v7 is neutral: cycles within the noise,
instructions -0.5% in every round. An absolute cursor and limit would save
three more instructions at a cost that spans the runtime, both backends,
diagnostics and heap tools; it is assessed and not built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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