Skip to content

perf: name the owner of the array: retention bucket by walking the edge graph - #258

Merged
Huxpro merged 4 commits into
new-lynxfrom
perf/lynx-heap-retainer-paths
Aug 31, 2026
Merged

Huxpro merged 4 commits into
new-lynxfrom
perf/lynx-heap-retainer-paths

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Summary

The follow-up Order #252 filed. Its probe names which constructors hold the surviving bytes and stops there deliberately, so array: was left as an owner-shaped hole — and after #250 it is the dominant named grower in the managed heap, 90.4% of the second cycle's retention. array is V8's own type for an unnamed backing store, so the bucket name describes the shape of the thing and never its owner.

Stacked on #252. Review that one first; this branch is the three commits on top.

The answer

array:'s dominant node is web-core's WebAssembly externref table. The walk lands on it in one hop — the node is held by exactly one edge — and the chain from the GC root names it:

synthetic --[1]--> synthetic --[10]--> synthetic --weak:26-->
  code --internal:wasm_weak_instance_list--> hidden --weak:0-->
    object:Instance --internal:exports--> object:Object
      --.__wbindgen_externrefs--> object:Table --[2]--> (the array)

That closes it against the mechanism already verified beside it. #252 established that every __Create* in @lynx-js/web-core hands new WeakRef(dom) to the Wasm element table, which is why object:WeakRef is exactly one node per painted element. So the two largest managed-heap rows are one owner, not two: the wrappers are the table's entries, and the array is that same table's backing store.

The size confirms it without appealing to the path

The node is 524,296 bytes = 65,536 slots × 8 B + an 8-byte header, and 65,536 is the smallest power of two above the 60,000 elements a 10,000-row page paints after #250. The same arithmetic lands on every reading this probe has ever produced:

point elements next 2ⁿ × 8 B observed delta
1k rows, pre-#250 7,000 8,192 65,536 64,824 −712
10k rows, pre-#250 70,000 131,072 1,048,576 1,047,864 −712
10k rows, post-#250 (node, not net) 60,000 65,536 524,288 524,296 +8

The residual is the same constant at two scales three doublings apart — a fixed offset from the rest of the bucket, not a fitted curve — and the direct node measurement is the header exactly.

And it explains the per-cycle growth the fold could only report

#252 recorded array: growing by roughly its own size every create-and-clear cycle and could not say why. The table is sized by elements ever created, not by elements alive. A second cycle takes the cumulative count to 120,000, which crosses into 131,072 slots and adds 524,288 bytes. The record observed 524,432.

So the growth is real and unbounded, and its owner is not Octane's code. It is a dependency's table that never releases capacity. What Octane controls is how many elements it asks that table to hold — which is exactly the quantity #250 reduced, and exactly why the retained total halved.

Changes

  • benchmarks/lynx-table/stages/heap-retainer-paths.mjs — the walk. immediateRetainers collects every edge landing on a node in one pass over the edge table; buildRootPaths reaches every node from the GC root once, keeping the edge that first found it. Both are recorded because they answer different questions: the retainer list is exact, a shortest chain from a root is a nomination.
  • benchmarks/lynx-table/stages/heap-retainer-paths.test.mjs — 8 tests.
  • heap-retention.mjs — --attribute <bucket>, off by default, plus the report section.
  • docs/measurement/heap-retention-attribution.md — the recipe, and the two limits that remain.
  • stages/results/c252-array-owner-10000.{json,md} — the record.

A full reverse index was written and then removed. It costs eight bytes per edge across millions of edges to answer a question asked about ten nodes, and the probe already declines to hold the raw snapshot for that reason. One sequential edge scan is exact and allocates nothing.

Validation

  • targeted tests: node --test benchmarks/lynx-table/stages/heap-retainer-paths.test.mjs — 8 pass, 0 fail; heap-retention-analyze.test.mjs — 10 pass, 0 fail.

  • every guard red-verified — each mutation broke its own test and restored:

    broken went red
    immediateRetainers keeps only a node's first retainer names every holder of a node, not only the first
    edgeLabel prints an indexed edge as a named one reads an element edge as an index… (and the retainer test, which asserts [2])
    rootPathFor answers [] for an unreached node answers null for a node no root reaches
    nodesInBucket hardcodes the self_size column reads the offsets the snapshot declares
  • the driver ran end-to-end at 10,000 rows, 3 repetitions, quiet host (load 0.02/CPU), clean tree; the result reproduced identically across three independent runs.

  • pnpm sync clean; pnpm format:files on every changed file.

  • pnpm format:check / pnpm typecheck / pnpm test — not run repo-wide. This branch touches only benchmarks/lynx-table/stages/ and docs/, no published package source.

The stamp #252 adds caught my own error within the hour. An exploratory run was taken while I had the recipe doc open, and its record came back dirty: true and said so in bold. By the rule that doc states — a dirty record is disqualified for comparison — it was discarded and re-run clean rather than shipped.

Risk / follow-ups

  • A retainer path names an owner in the heap, not a line of source. object:Table is where the bytes live; going from there to the call that grew it is still reading. Under The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230 the path and the sizes are verified; "this is why the bytes survive" is not claimed beyond the one-hop retainer, which is exact.
  • This probe does not rank owners. Self size says how big a node is and the chain says who reaches it; neither says how much would be freed if that owner let go. That is a dominator-tree question and is not answered here.
  • No package source is touched. Nothing about the runtime changes; this is an instrument and a record.
  • The finding is upstream, not ours. A follow-up worth considering is whether web-core's table can reuse slots freed by a clear, but that is a @lynx-js/web-core change and belongs in that conversation, not this one. What is actionable on our side is already named: fewer painted elements is fewer table slots, which is Octane paints 7 elements per benchmark row where Vue paints 4 — audit the row's element diet; it is also the ART-ceiling denominator #242's element diet.
  • Branch naming. The harness assigned claude/octane-issue-66-phase-a-7wz97z for this session, but create-a-pr requires a feat/|fix/|docs/|test/|perf/ topic branch so label-pr.yml can read the type. A topic branch was used; flagging the conflict rather than resolving it unilaterally.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Huxpro and others added 3 commits August 31, 2026 07:45
The fold names which constructors hold the surviving bytes and stops, because
self size over every node is exact where a retained size double-counts. That
was enough to close `object:WeakRef` with a mechanism and not enough to close
`array:`, which after #250 is the dominant named grower in the managed heap.
`array` is V8's own type for an unnamed backing store, so the bucket name is
the shape of the thing and never its owner.

This adds the walk the fold declines: `immediateRetainers` collects every edge
that lands on a node in one pass over the edge table, and `buildRootPaths`
reaches every node from the GC root once, keeping the edge that first found it.
Both are recorded because they answer different questions — the retainer list
is exact, while a shortest chain from a root is a nomination to go and read.

Off unless `--attribute <bucket>` is passed. It costs an edge pass and a
breadth-first walk on a snapshot the probe otherwise drops as soon as it is
folded, which is worth paying once a bucket has earned it by size and by
growing per cycle, and worth paying never otherwise.

Eight tests, each red-verified: keeping only a node's first retainer, printing
an indexed edge as a named one, spelling an unreachable node as an empty path,
and hardcoding the `self_size` column each break their own test and restore.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
…s not say

The recipe's closing section said the probe cannot name what points at a
bucket. It can now, so the section is replaced rather than appended to: a doc
that describes a missing capability is worse than one that describes none.

Two limits stay, and they are the ones a reader is likely to overstep. A
retainer path names an owner in the heap, not a line of source. And it does
not rank owners: self size says how big a node is and the chain says who
reaches it, but neither says how much would be freed if that owner let go,
which is a dominator-tree question this probe does not answer.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
The bucket is web-core's WebAssembly externref table. The walk lands on it in
one hop — the node is held by exactly one edge, `object:Table` via `[2]` — and
the chain from the GC root runs through `.__wbindgen_externrefs` on the Wasm
instance's exports.

That closes it against the mechanism already verified beside it. Every
`__Create*` in web-core hands `new WeakRef(dom)` to that same table, which is
why `object:WeakRef` is exactly one node per painted element. The two largest
managed-heap rows are therefore one owner, not two: the wrappers are the
table's entries and the array is the table's backing store.

The size confirms it without appeal to the path. The node is 524,296 bytes:
65,536 slots at 8 bytes, plus an 8-byte header. 65,536 is the smallest power
of two above the 60,000 elements a 10,000-row page paints after #250. The same
arithmetic lands on every earlier reading — 8,192 slots at 1,000 rows, 131,072
before the fold — with a residual of exactly -712 bytes at two scales three
doublings apart, which is a fixed offset from the rest of the bucket rather
than a fitted curve.

And it explains the per-cycle growth the first record could only report. The
table is sized by elements ever created, not by elements alive: a second
create-and-clear takes the cumulative count to 120,000, which crosses into
131,072 slots and adds 524,288 bytes. The record observed 524,432.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
--attribute paid the edge scan and whole-graph BFS on all four captures
of every repetition while only the median afterClear table is recorded;
the other three phases now skip the walk, which is the file's own
'worth paying never otherwise' note applied to itself.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
@Huxpro
Huxpro changed the base branch from perf/lynx-heap-retention-attribution to new-lynx August 31, 2026 15:17
@Huxpro
Huxpro merged commit 52c7a8b into new-lynx Aug 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants