Skip to content

perf(lynx): stop describing detaches a clear's own destroy performs - #249

Merged
Huxpro merged 4 commits into
new-lynxfrom
perf/lynx-clear-stops-describing-detaches
Aug 30, 2026
Merged

Huxpro merged 4 commits into
new-lynxfrom
perf/lynx-clear-stops-describing-detaches

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Summary

E2 proper, first cut. Stacked on #248 → #245 → #243 — review in that order.

Attribution first, per #241. A deterministic probe over the benchmark row shape
priced a table clear at 10 synthesized commands per row, and found that
2 of the 10 describe work the next command already performs. They are gone.

Why

The clear has two routes, and they are not close:

8,000-row clear synthesized commands wall clock
certified direct plan (prepareDirectFullTeardown) 0 ~17 ms
records-map expansion (expandRecordsRunTeardown) 80,000 ~230 ms

Same container, same program, same final tree, same host-call count (#245 made
both one call per row). The only difference is whether the incremental compact
accepted — and parking a single explicit host above the run's id space is enough
to decline it, which is the situation any page with a toolbar is in.

That 13× is the headline E2 finding, and it is not what this PR fixes.
Closing it means giving the records-map route its own certifier, which is a
design change, not an overnight one. Reported to #230 with the sequence answer;
this PR takes the part of the gap that is provably dead work.

The dead part

Expanding a destroy-run emitted, per benchmark row:

commands op why
7 destroy one per host
2 event (detach) subsumed
1 remove root removal

The 2 detaches are redundant with the destroy that retires the same host in
the same expansion. destroy's apply already calls
removeAllNativeEvents(state, node, teardownMaySkipUnbind()) — the same
function the detach command's operation would reach, with the teardown flag read
live in the apply phase rather than decided when the run was expanded. Since
#245 the lowering was already declining to journal them; this stops building
them.

Verified, not assumed: instrumenting the expansion shows
{destroy: 7000, remove: 1000, event: 2000} per 1,000 rows before and
{destroy: 7000, remove: 1000} after.

Changes

expandRecordsRunTeardown gains one predicate, state.lists.size !== 0:

  • No native list → the detaches are not described. 100,000 → 80,000
    commands at 10k rows.
  • A native list on the container → described exactly as before, in the same
    [detach][remove][destroy] order. A list recycles elements the driver does not
    own and can hand one back still bound, so its unbinds stay explicit; leaving
    them to destroy would also reorder the PAPI stream from unbind-then-remove to
    remove-then-unbind. Not a change worth making in the one case this harness
    cannot exercise. Reading the predicate at expansion time can only ever describe
    more work than the apply performs, so the conservative direction is safe.

Separately, the destroy apply operation stops carrying new Map(record.events).
Both sites that read an operation's events are the recreate and visibility
branches; the destroy branch reads the live state.nativeEvents entry for the
node. The snapshot was one map allocation per destroyed host that nothing read —
70,000 of them at 10k rows. Dropping the field from the union lets the
compiler prove nothing else wanted it.

Validation

  • pnpm format:check — via pnpm format:files on both changed files

  • pnpm typecheck — see below

  • pnpm test — not re-run; see below

  • targeted tests:

  • npx vitest run --project lynx — 48 files, 731 passed (730 before, +1 new).

  • New regression, red-verified. releases a cleared run's listener journal through its destroy is the companion to perf(lynx): stop describing unbinds a teardown's own destroy subsumes #245's per-row oracle: that one pins
    what a clear spends, this one pins that it still releases. It clears a
    4-row run through the records-map route, asserts the clear costs
    {remove: 4, flush: 1}, then asserts disposal afterwards emits no
    setEvent — a listener left in the journal would outlive its record and be
    unbound at disposal. Broke destroy's removeAllNativeEvents call and it
    went red with 8 stale setEvents (2 listeners × 4 rows); restored.

  • pnpm typecheck:files — host-driver.ts clean. host-driver.test.ts reports
    40 errors, all pre-existing: stashed, re-ran, got 40; diff of the sorted
    multisets is empty.

  • pnpm sync — clean.

  • pnpm test (repo-wide) was run on the perf(lynx): stop describing unbinds a teardown's own destroy subsumes #245 ancestor and its 3 failures proven
    pre-existing there against base 8938c1260. This commit touches the same two
    files plus a changeset; the lynx project suite is the meaningful gate.

Risk / follow-ups

  • Does this change the sequence? (The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230 protocol) Yes, within E2 — no
    reordering of the train.
    E2 → E3 → E1 stands. What changes is E2's own
    content: the 15.5× route gap means the remaining E2 work is "make the
    declined-compact route cost what the certified route costs"
    , not "make
    teardown cheaper"
    . Teardown is already cheap on one of its two routes. Full
    reasoning and the sequence answer are on The create residual: attribute it, tax-test it, then extend compiled programs to steady-state mounts (E-train) #230.
  • The wall-clock half of Clear/teardown pays 2.6–4× the peers' JS volume, regime-invariant, family-wide — attribute and shrink it (E2's cost half) #241's oracle is still not measured. clear@10k ≤
    1.15× react and heapMtsAfterClear ≤ upstream both need the web harness, and
    the app cannot be built in this environment (npx rspeedy build → 404 from the
    proxy). What is verified is deterministic: 20% fewer synthesized commands, one
    fewer map allocation per destroyed host, clear-time event calls still 0.
  • Wall clock is deliberately not claimed. At 8,000 rows the clear measures
    239 ms before, 225 ms after by median of seven warm samples — inside a
    ±50 ms spread in this container. A 20% command cut ought to show, and it may;
    this environment cannot say so. The counters are the claim.
  • Which route the real app takes is not established here. The probe proves
    both routes exist and what each costs; it does not prove which one a device
    build resolves to, because that needs the browser harness. The earlier
    dispatch-site instrumentation suggested the declined route, which is why this
    PR targets it — but treat that as hypothesis, not verified.
  • Conflict discipline: stacked on perf(lynx): drop the teardown record mirror #248 rather than branched off new-lynx,
    since both touch host-driver.ts and the standing rule is that the later
    change yields to the earlier. No force-pushes on any open PR.
  • Branch-name deviation: the harness assigned
    claude/octane-issue-66-phase-a-7wz97z, but create-a-pr mandates a perf/
    topic branch so label-pr.yml can derive the type label. Topic branch used;
    flagging rather than silently picking a side.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Expanding a `destroy-run` against ordinary records synthesized one `event`
command per listener on its way to the `destroy` that retires the same
host. `destroy` already ends the listener lifetime: its apply calls
`removeAllNativeEvents` with the teardown flag read live, in the apply
phase, rather than decided when the run was expanded. The detach commands
existed only to describe it.

Measured on the benchmark table row (view.row over three text cells with
their carriers, two tappable), through the records-map route a table clear
actually takes once anything on the page owns a higher host id:

  per row   before   after
  commands      10       8
  destroy        7       7
  remove         1       1
  event          2       0

At 10,000 rows that is 100,000 synthesized commands down to 80,000.

A container that owns a native list keeps describing them. A list can hand
a recycled element back still bound, so its unbinds stay explicit — and
leaving them to `destroy` would also reorder the PAPI stream from
unbind-then-remove to remove-then-unbind, which is not a change worth
making in the one case that cannot be exercised from this harness.

The `destroy` apply operation also stops carrying a copy of the record's
events. Neither apply branch that reads an operation's `events` is the
destroy branch, which reads the live `state.nativeEvents` entry instead, so
the snapshot was one map allocation per destroyed host that nothing read.
Dropping the field lets the compiler prove that.

Wall clock is not claimed. At 8,000 rows the clear measures 239 ms before
and 225 ms after by median of seven, inside a spread of roughly 50 ms in
this environment; the command and allocation counts are the deterministic
half and the only half asserted.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
#241 sets a retention oracle on `heapMtsAfterClear@10k` and nothing in this
repository names that metric, so grepping `benchmarks/` for it returns nothing
and invites the conclusion that the oracle cannot be measured. It can: the
instrument lives in the campaign harness and reads the metric over CDP.

Writes down what the instrument does, why a post-collection reading and a
retained peak are different quantities that do not settle each other, how to
build a single entry bundle per arm rather than the whole row ladder, and how to
drive the memory block directly instead of paying for every latency case first.

Includes the units trap: the harness records bytes, #241 quotes decimal MB, and
the obvious `/1024/1024` prints MiB — a 4.9% difference, wider than most changes
move the number.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
claude added 2 commits August 30, 2026 12:49
Gate-review fix on the E2 train: the subsumed-detach skip keyed on the
batch's whole destroy set, so a batch that destroys an id and re-creates
it would skip a detach on the new incarnation, leaving the native binding
installed on a live element. The skip now asks whether a destroy of that
id comes after the detach; red-verified with a destroy/re-create/bind/
unbind batch.

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-teardown-mirror-verdict to new-lynx August 30, 2026 12:50
@Huxpro
Huxpro marked this pull request as ready for review August 30, 2026 12:50
@Huxpro
Huxpro merged commit 432c648 into new-lynx Aug 30, 2026
1 of 2 checks 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