Repository navigation
perf(lynx): build native lists through direct first-screen emission - #113
Conversation
The direct applier writes the rendered record tree straight to the Element PAPI — no command batch, no prepared operation list, no cloned record maps — and refused any tree containing a `<list>`. That was the right call while such a page could not be adopted anyway; now that it can be, the refusal was the remaining cost on exactly the pages a fast first screen is for. A `<list>` breaks the applier's shape twice. Its element comes from `__CreateList` with the recycling callbacks passed at creation, not from `__CreateElement`; and its rows are not attached to it, because the platform materializes a row when it needs one, so the walk records every row and descendant without creating anything — the same operations the staged path skips. The element is still created on the way down, where its unique ID lands in the order the staged path assigns it: a list whose element were created after its subtree would hand a later sibling the lower ID. Only the row metadata waits for the way back up, because it is read off records the walk has not created yet. `createNativeListNode` splits into `beginNativeListNode` and `publishNativeListItems` for that, and the staged path calls the composition. Emitting as it walks means the applier cannot discover a malformed list halfway and stop — a half-painted page is the one state the staged path never produces — so it runs the real validators over the tree first and hands anything it cannot vouch for back, with nothing created and the diagnostic raised from where it has always been raised. A host offering no `__CreateList` falls back for the same reason: that page is owed the report. At 1,000 rows the first screen goes from a median 42.5 ms to 29.5 ms, the two distributions disjoint across three passes each. Element PAPI traffic is identical in both arms — 21 calls — which is the point: what this removes is Octane's own staging, not one host call. Refs #66.
|
Full Every failure reproduces on the integration base
The remainder are build/spawn timeouts on this 4-CPU container, not assertions: The diff in this PR is confined to Generated by Claude Code |
… paints Before this branch a page holding a native <list> was declined by the direct first-screen applier and rebuilt through the staged path, so prepare's final validation raised `main-thread ref X is assigned to hosts N and M` with zero PAPI calls spent. C3 makes such a page directly buildable, and the direct path carried a pre-walk for only one of prepare's two non-list diagnostics: the main-thread/background event collision. A duplicated ref therefore survived to `installMainThreadRef`, which reports it as `is already mounted` — a weaker message, raised mid-mount, after elements exist. That is the half-painted page the pre-walk exists to prevent. Extend the pre-walk to carry both diagnostics, with prepare's exact ref message and its visibility rule. The walk is now unconditional: a background listener is announced by the envelope, but a ref is announced by nothing but the host's own props, and this applier is exported, so no envelope field may make the check skippable. It is a second read-only pass over a tree the function already scans for a <list>. This is where the pre-check fix on new-lynx (e6b2898) lands once #112 retires `firstScreenTreeIsUnadoptable`: the same two diagnostics, replayed from the one place that still decides whether to paint. Regressions: the two gate scenarios now also assert nothing was painted, and a new one puts the duplicate on two rows of one list — rows own no element during the first screen, so no mid-mount check can ever see it. Both ref scenarios were verified red without the check (2 failed | 25 passed). Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
|
Your duplicated-main-thread-ref regression caught a real defect in this PR. Fixed in What was broken. Before this branch, a page holding a native Where your The walk is now unconditional. A background listener is announced by the envelope, so a page with none could skip a collision-only walk; a Regressions. Both of your scenarios now also assert nothing was painted ( Re-validated at the stack tip after the cascade: One correction to this PR's body I owe you: the Risk bullet says the pre-walk is "paid only by pages that contain a Generated by Claude Code |
|
Correction to my previous comment: I said I would fold that Risk-bullet fix into the PR body, and I am deliberately not doing it. The only PR-editing tool available in this session round-trips the body lossily — it strips So the corrected bullet stands here instead of in the body:
Happy to apply it to the body directly if you would rather it live there. Generated by Claude Code |
Capture journaled the epoch with one copy of the counter sum and adoption compared it with another; a counter added to only one side would silently break staleness detection (every list adoption repairs, or a stale tree adopts). One listRecyclingEpoch() now owns the formula for both sides. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
Summary
Stacked on #112 (
feat/lynx-adopt-native-list). Issue #66 Phase C, C3 — thelast step of the phase.
The direct first-screen applier writes the rendered record tree straight to the
Element PAPI: no command batch, no prepared operation list, no cloned record
maps. It refused any tree containing a
<list>. That was the right call whilesuch a page could not be adopted anyway — painting a page the background would
then re-render is worse than not painting it. #112 made it adoptable, so the
refusal became the remaining cost on exactly the pages a fast first screen
exists for.
A
<list>breaks the applier's shape twice over:__CreateElement. It comes from__CreateList,with the three recycling callbacks passed at creation.
componentAtIndexwhen it needs one, so the walk records every row and everyrow-descendant without creating anything — exactly the
createoperationsthe staged path skips.
Creation order is a contract, and it decided the design
The list's element is created on the way down, so its unique ID lands in the
same order the staged path assigns it. A list whose element were created after
its subtree would hand a later sibling the lower ID, and a page's element
identity would depend on which applier painted it. Only the row metadata waits
for the way back up, because it is read off records the walk has not created yet.
That is why
createNativeListNodesplits intobeginNativeListNode(create +register the main-local list state) and
publishNativeListItems(build thedescriptors,
setAttribute('update-list-info', …)). The staged path calls thecomposition and is unchanged. The differential fixture carries a
<text>siblingafter the list precisely to hold this property — remove the sibling and the
ordering bug is invisible.
It asks before it paints, because it cannot stop halfway
Emitting as it walks means the applier cannot discover a malformed list partway
through and back out: that leaves a half-painted page, which is the one state the
staged path never produces. So it runs a pre-walk and hands anything it cannot
vouch for back to the staged path with nothing created, where the diagnostic is
raised from where it has always been raised.
The pre-walk runs the real validators —
createLynxListItemDescriptorandplanLynxListUpdate— over the same nodes rather than restating their rules, andtracks the two placement rules the prepare walk owns (nested
<list>,<list-item>outside a list) alongside. Ranges are transparent in it, for thesame reason they are in C1's predicate:
@forproduces no record, so an authoredlist does not own its rows as children, and a reader stopping at the immediate
children would validate an empty list, wave it through, and fault at publish —
the half-painted page this exists to prevent.
Two trees still take the staged path, and both deliberately:
__CreateList. That page cannot build a<list>atall and is owed the diagnostic, not a silent fallback.
Measurement
Same harness and fixture as #112: a
template-created shell wrapping a<list>whose rows arrive through a keyed
@for, each row a<list-item>with threechildren. Arms by checking out
host-driver.ts; 21 samples per pass after 3warmups, each in a fresh environment. Every sample of both arms was asserted to
have adopted.
Each cell is a median of 21 samples. The 1,000-row rows take the middle of three
passes — paint: staged 42.5 / 40.9 / 45.7, direct 28.5 / 29.5 / 31.4 — so the two
distributions are disjoint (slowest direct sample 31.4 ms, fastest staged
40.9 ms). The 50-row page ran two passes each, so both are given rather than
averaged.
Element PAPI traffic is identical in both arms at both sizes: 21 calls. That
is the point. What this removes is Octane's own staging, not one host call; the
platform sees the same page built the same way.
The arc across the whole phase, on the same 1,000-row page:
Every figure is a lower bound on the real improvement: the harness hands the
background's commit over immediately, where a real page pays a bundle load and a
cold render on another thread first.
Red/green
Every guard below was produced by breaking the implementation on this branch and
running
--project lynx(440 tests).hasNativeListTopologynever settruefalseThe one unguarded line, stated rather than papered over
state.hasNativeListTopology = truehas no test that fails without it. It isunobservable on a direct-painted container today, by construction: the only
caller of
applyLynxFirstScreenDirectismain-thread.ts:1907, on thefirst-screen source container, and the staged
prepareLynxHostBatch(source, …)only runs when the direct applier returned
false. So a container is never bothdirect-painted and batch-prepared, and the flag's consumers — the compact-run and
lazy-public-instance fast paths in the staged prepare — never read it on a
container this path built.
It is set anyway, because the flag is a property of the container's topology,
not of the applier that produced it, and the next caller of this function should
not have to rediscover that. I did not write a test for it: the only test that
could fail would have to reach past the public entry point into
LynxHostState, which.rulesync/rules/testing.mdforbids, and a contrivedscenario asserting an internal boolean would protect the current routing rather
than the behavior.
Validation
pnpm format:checkpnpm typecheckpnpm test— ran on this head: 2,185 files / 20,971 tests passed, 11 files/ 5 tests failed. Every failure reproduces on the integration base
origin/new-lynxin this container and none is inpackages/lynx— sixre-verified there one by one, the rest are build/spawn timeouts on a 4-CPU
box. Full breakdown in this comment.
vitest run --project lynx→ 440 passed (32 files), including 12in
packages/lynx/tests/first-screen-direct.test.tsnode benchmarks/bench.mjs --quick --ratios lynx-list→ PASS, allocationratio 0.012x eager, unchanged
pnpm sync— no generated changesnative-demo— one of the tworspeedy-pluginfailures issue #66 §2.3 records aspre-existing here — is among them.
Risk / follow-ups
<list>— a list-free page still short-circuits onfirstScreenTreeHasList.It is the price of never half-painting; at 1,000 rows the paint still drops
13 ms net.
If a new list rule lands somewhere other than
createLynxListItemDescriptor,planLynxListUpdate, or the two placement checks, the pre-walk would not seeit and the applier could fault mid-walk. A single "would the staged path accept
this list?" entry point both paths call would close that; it is not this PR.
compareFirstTreestill walks all 4,002 records on the 1,000-row page tocompare 2 physical nodes — measured at 11.1 ms in feat(lynx): adopt a painted native list into the background root #112's instrumentation.
Narrowing that walk is the natural next increment.
Provenance
agent-authored)Generated by Claude Code