Repository navigation
perf(lynx): stop describing unbinds a teardown's own destroy subsumes - #245
Merged
Merged
Conversation
Clearing a template run cost one Element PAPI call per row plus one per listener on that row. A `destroy-run` expands to a listener detach per event site, a root remove per row, and a destroy per host, and the detaches were journalled and lowered like any other event change, so the lynx-table row -- `view.row` over three text cells, two of them tappable -- spent three host calls per row to clear. At 10k rows that is 30,001 calls, of which 20,000 describe listeners on hosts that no longer exist by the end of the commit. Only the root removal is observable. Dispatch already refuses a token whose record was deleted, whose generation moved on, or whose host is no longer root-connected, and a destroy does all three, so a binding left installed on a detached element cannot reach a listener. The certified direct teardown plan has skipped these unbinds since it was written; this carries the same property to every other teardown route, which is the route a table clear takes as soon as anything else on the page owns a higher host id. A clear now costs one host call per row whatever the row carries. Preserved: main-thread worklet registrations are still released explicitly, because the engine holds those and only release ends their lifetime; native-event bookkeeping is still cleared, so no entry outlives its record; and any native list topology keeps the explicit unbind, because a list recycles elements the driver does not own and can hand one back still bound. Tests: the partial destroy-run test now asserts zero teardown event calls plus the semantic property that makes that safe -- neither destroyed token resolves while a survivor's still does. A new oracle pins one host call per row across 1/4/16 rows and 0/1/2 listeners, on both the certified and the general expansion route. Both were confirmed red against the unpatched driver. Behaviour note: the batch-wide destroy set is now built on first use rather than at the first destroy command, so a malformed destroy id in a batch that also detaches listeners is reported at the detach instead of at the destroy. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
This was referenced Aug 30, 2026
Huxpro
changed the base branch from
test/lynx-teardown-mirror-differential
to
new-lynx
August 30, 2026 12:49
Huxpro
marked this pull request as ready for review
August 30, 2026 12:49
1 task done
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.
Summary
E2 proper for #230, against #241's cost oracle. Stacked on #243 (the
teardown-mirror differential), which is the control this change is measured
against — review #243 first.
#241 says attribute first: "count them per row and price them." So I did.
Attribution
A deterministic probe (FakeNode host,
papi.callstally) over the lynx-table rowshape —
view.row+ threetextcells + their text carriers = 7 hosts, two ofthem tappable — priced a clear at exactly 3 host calls per row, invariant
across 500/1000/2000 rows and across teardown routes:
setEvent(listener detach)remove(root removal)destroyAt 10k rows that is 30,001 calls, of which 20,000 describe listeners on hosts
that no longer exist by the end of the commit — 66.7% of the clear's entire
host-boundary traffic.
Why the detaches are not observable
Not an assumption —
resolveLynxHostNativeEventalready refuses a token on anyof: the record is gone (
deleteRecordat destroy), the generation moved on, orthe host is no longer root-connected (
remove, which precedes destroy). Adestroy trips all three. A binding left installed on a detached element cannot
reach a listener.
And the codebase already relies on this:
prepareDenseTeardownwraps its entireevent-detach loop in
if (!plan.direct), so the certified direct teardown planhas skipped these unbinds since it was written. This change carries that same
property to every other teardown route.
That matters because
plan.directis unreachable exactly when it would helpmost. Instrumenting the dispatch site showed a bench-shaped paint→clear resolves
dense: false, mirror: true— records stay a map, so the direct plan is nevereven attempted and the clear pays full freight. Keeping the
compactHostsrefusal (as the ruling requires) means that is the normal route, not a corner.
What changed
removeNativeEventgains ateardownmode that skips the PAPI unbind and thesuperseded-binding scan. It is passed at the three teardown sites: the certified
plan's detach loop, the
destroylowering, and — as an outright skip of thejournalled operation — the
eventcommand lowering when the same batch destroysthat host.
Deliberately preserved:
an explicit
release()ends their lifetime, whatever happens to the element.state.nativeEventsentryoutlives its record.
elements the driver does not own and can hand one back still bound. Read live
at each use rather than snapshotted, since a list can appear inside the very
batch being lowered, and the two readers run in different phases.
Result
A clear costs one host call per row, whatever the row carries. At 10k rows:
30,001 → 10,001.
Validation
pnpm format:checkpnpm typecheckpnpm testtargeted tests:
npx vitest run --project lynx— 730 passed (729 before this change).Both tests red-verified against the unpatched driver, which took two
attempts worth recording:
expected [[…], […]] to deeply equal [].{setEvent: 1, remove: 1, flush: 1}vs{remove: 1, flush: 1}— but only after I fixed it. My first versionpassed unpatched, because its clean-paint scenario hit
plan.direct, whichalready skipped the detaches. It was measuring the already-fast path and
protecting nothing. It now parks an explicit host above the run's id space
so the incremental compact declines, and asserts the bound on both
routes.
pnpm format:fileson both changed files — clean; changeset added.pnpm test(repo-wide) has now finished: 26,770 passed, 1 skipped, 3failed across 2,451 test files. I said I would confirm whether the failures
are pre-existing rather than let them pass silently, so I checked instead of
asserting: with
packages/lynx/src/core/host-driver.tsand its test filechecked back out to the base commit (
8938c1260), all three reproduceidentically.
rspeedy-plugin›native-demo.test.ts› escalates cleanup for a detached descendant after its leader exitsdrei-adapted-browser›upstream-e2e.browser.test.ts› should match previous oneoctane-events-browser›suspense-hydration.test.ts› restores focused input and its selected text after a keyed DOM reorderNone of the three imports the host driver, and the diff touches no package
they reach. Two are headless-Chromium behaviours in this container (a WebGL
canvas whose ready event never fires; text-selection restore across a keyed
DOM reorder). The third asserts a 100 ms SIGTERM→SIGKILL process-group
escalation and fails deterministically here — in isolation, at base, under no
load — so it is this container's process semantics, not a scheduling flake.
Risk / follow-ups
1.15× react and
heapMtsAfterClear≤ upstream both need the web harness, andthe app cannot be built in this environment (
npx rspeedy build→ 404 fromthe proxy). What is verified is the deterministic half — clear-time event
calls = 0, one host call per row — and the call-count reduction that follows
from it. Whether 20,000 fewer PAPI calls closes the 2.6× ratio is
hypothesis, not verified; it needs a run on the 3-lane campaign.
built on first use rather than at the first
destroycommand, so a malformeddestroy id in a batch that also detaches listeners is reported at the detach
rather than at the destroy. Same error, earlier point. No test pinned the
ordering.
event-operation skip is a lowering-time decision; the expansion stillemits the detach commands, so the command volume through the generic applier
is unchanged (~100k at 10k rows). Cutting those too would need
plan.eventCommandsrenegotiated with the certified path — a larger change,deliberately not folded in here.
claude/octane-issue-66-phase-a-7wz97z, butcreate-a-prmandates aperf/topic branch so
label-pr.ymlcan derive the type label. Topic branch used;flagging rather than silently picking a side.
Provenance
agent-authored)Generated by Claude Code