Skip to content

perf(lynx): decline an unadoptable first screen before painting it - #110

Merged
Huxpro merged 5 commits into
new-lynxfrom
perf/lynx-decline-unadoptable-first-screen
Aug 20, 2026
Merged

Huxpro merged 5 commits into
new-lynxfrom
perf/lynx-decline-unadoptable-first-screen

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

Stacked on #109. Issue #66 Phase C opener.

A first screen holding a native <list> was rendered, built into a full command
batch, given a host container, staged, prepared, applied, planned as a native
list, refused by adoption capture, and then torn all the way back out — to reach
a verdict that never depended on any of it having happened.
captureLynxFirstTree refuses every root holding a <list> outright, and the
renderer's record tree already carries every element type and prop that refusal
reads. So the question is now asked there, before the container exists. A page
whose answer is "decline" retires with no container, no batch, and no Element
PAPI traffic at all.

The change is a pure predicate over LynxFirstScreenDirectNode[] plus five
lines wiring it into renderFirstScreenNow.

What compiled pages actually look like

Every list fixture in the suite nested its rows directly under the <list>,
which no .tsrx produces. Compiling tests/_fixtures/native-list.lynx.tsrx with
lynxMainThreadRenderer shows the real lowering:

const __octaneUniversalPlan1 = __octaneUniversalPlan('lynx', {
  "kind": "template",
  "slots": ["r"],
  "create": (env, values) => {
    let n0 = env.h("list");
    env.p(n0, "id", "native-feed");
    env.s(n0, values[0]);
    return n0;
  }
});

with the rows in that one child hole as __octaneUniversalFor(...). Rendering it
gives this record tree — the thing the pre-check reads:

host <list> {"id":"native-feed"}
  range
    host <list-item> {"reuse-identifier":"feed-row","item-key":"a"}
      host <text> {}
        host <#text> {"value":"A"}
  range
    host <list-item> {"reuse-identifier":"feed-row","item-key":"b"}
      ...

Two properties follow, neither of which any fixture covered. A <list> created
by a template still records as an ordinary list host. And its rows are
not its own children — one range per row sits in between — so a reader
stopping at the immediate children would validate an empty list, decline, and
swallow every row defect, while still passing a decline test. That is why
each of the two realistic fixtures (keyed-loop and template-lowered) carries both
a decline test and a duplicate-item-key test: making ranges opaque turns both
duplicate tests red and leaves both decline tests green.

Both walks are also iterative, because a range chain is a chain of nested
directives and nothing in the first-screen pipeline may cap a depth the renderer
accepted (#90).

It must not swallow a diagnostic

Skipping a build must never skip an error. The pre-check answers true only
for a tree the staged path would have accepted, and it establishes that by
running the real validators rather than restating their rules: it calls
createLynxListItemDescriptor and planLynxListUpdate from core/list.ts over
the same nodes and treats a throw as "not a decline, keep going". The two
placement rules the prepare walk owns — nested <list>, and <list-item> not
directly under a <list> — it tracks alongside as it walks.

That covers eight of the nine list diagnostics. The ninth is a host that offers
no list PAPI: without __CreateList a <list> cannot be built at all, and an
application using a documented element deserves that report rather than a silent
skip, so the whole pre-check is gated on papi.list !== undefined.

Seven tests hold each diagnostic to its current site.

Measurement

Real installLynxMainThread first-screen path, 1,000-row fixture (4,002 logical
hosts: a <view> shell, one container, three <view> children per row). Arms
taken by stashing the change so both run the same harness on the same fixture;
21 samples per pass after 3 warmups, each in a fresh environment. Element PAPI
traffic counted by wrapping every function-valued __* global before the PAPI
captures them, and asserted identical across all 21 samples of a pass.

A second fixture differing only in element types (view/view in place of
list/list-item) is the regression control.

fixture PAPI calls median first screen
native list, before 18 37.8 ms
native list, after 0 5.1 ms
list-free control, before 20,012 107.9 ms
list-free control, after 20,012 111.2 ms

Medians of four before-passes and three after-passes. The list distributions are
disjoint — slowest after-sample 12.0 ms, fastest before-sample 30.8 ms.

Only 18 PAPI calls in the before arm because an unscrolled native list creates no
cells: the platform materializes rows through the recycling callbacks. So the
~33 ms removed is Octane's own work behind those calls — the batch, the
container, the prepare and apply walks, the list plan over 1,000 descriptors, the
capture, and the teardown. The 5.1 ms that remains is the render producing the
records the verdict reads.

The control resolves nothing end to end: its between-arm spread (104.0–110.9
before, 104.7–116.8 after) is the size of its within-arm spread. Timed directly
instead, 200 calls after 200 warmups on the same rendered tree:

tree hosts verdict median p95
list-free 4002 false 0.063 ms 0.117 ms
list 4002 true 0.501 ms 0.572 ms

0.063 ms is 0.06% of that page's ~108 ms first screen. The list tree costs more
because it runs the real validators over 1,000 descriptors, and it replaces
~33 ms of build-and-discard.

The measurement harnesses were temporary and are not in this diff; the numbers
they produced are in docs/lynx-specialized-target-l0.md §8.

Two existing tests changed rather than being deleted

Both pinned build-then-teardown, which is exactly what no longer happens.

  • declines a synchronous first screen holding a native list without faulting
    is now …without painting it, and asserts the stronger contract: no flush
    ever carried the list or its shell.
  • retries deferred cleanup for a declined first screen had become
    unreachable — its __RemoveElement that always throws is never called now.
    It is repurposed to announces readiness for a declined first screen with no cleanup to defer, keeping the same hostile host and asserting removals === 0
    with readiness announced on the first attempt.

An unrelated format:check failure the stack was carrying

pnpm format:check failed on this branch for three committed benchmark result
JSONs — and would fail the same way on four branches below it. All three are
formatted correctly on new-lynx; the unformatted copies came in with the stack:
stages/results/live-1000.json and live-10000.json via 888d9034f/88e9db5f0
(first carried by #102), and prototype/results/u0-block-core-counts.json new in
781e4fca3 (#107).

Repaired here rather than at the source, because both of those branches are
published and under review and fixing them in place would rewrite history four
and two branches deep. Whitespace only — each file reparses to a byte-identical
JSON value, checked before committing.

One changeset amended

.changeset/lynx-first-screen-declines-native-list.md is merged but unreleased,
and its last paragraph promised exactly this work while predicting a different
route to it ("needs the prepared batch to publish what it staged"). Left alone it
would ship in the same CHANGELOG entry as this change, contradicting it. Its
closing paragraph now records that the item is closed and by what means.

Validation

  • pnpm format:check — clean repo-wide (after the repair above)
  • pnpm typecheck — clean
  • pnpm test — not completed in this container: the full run exceeded a
    60-minute cap. The projects this change can reach were run explicitly
    instead, below.
  • --project lynx — 32 files, 434 passed
  • --project octane --project octane-prod — 841 files, 12,436 passed,
    4 skipped, 0 failed
    ; 2 files errored (see below)
  • packages/lynx/tests/first-screen.test.ts — 21 passed
  • node benchmarks/bench.mjs --quick --ratios lynx-list — PASS, 0.012x eager
    (12 physical cells for 1,000 logical items, 988 reuses, 0 after teardown).
    This is the exit gate Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66 §5 names for Phase C; C1 does not touch the list
    runtime.

The 2 errored files, and why they are not this change

packages/octane/tests/react-hosted/web3-island.test.ts (once per project) fails
with Hook timed out in 10000ms while building the rainbowkit hydration
fixture. No test assertion fails; the file errors in its setup hook and its 2
tests are skipped.

I initially measured it as a regression and was wrong. One run on the base
(fbccb04c1) passed and one on this head failed — but both sat on the timeout
boundary, 10.25 s and 10.02 s against a 10,000 ms hook cap, and both failures
came directly after heavy load (a 60-minute suite, then a benchmark). Three
consecutive standalone runs on this head all pass. It is a threshold flake on a
fixture build that takes about as long as its own timeout, and nothing in this
diff is reachable from that file — the change is confined to packages/lynx/src,
which the octane project does not import.

Red/green on the pre-check, each break run against the full file:

deliberate break result
predicate always true 9 failed, 8 passed
predicate always false 9 failed, 8 passed
drop the nested-<list> guard 1 failed, 16 passed
drop the <list-item> placement guard 1 failed, 16 passed
drop the list.ts validators 1 failed, 16 passed
drop the papi.list gate 1 failed, 16 passed
ranges opaque in the host-children walk 2 failed, 19 passed
restored 21 passed

The first six rows were run against the 17-test file, before the two realistic
fixtures existed; their counts are from that run. The predicate always false
break re-run against the final 21-test file fails 13.

Two breaks came back green the first time and needed better fixtures. The
placement break: the stray-row fixture had no well-formed <list> in it, so the
predicate declined to claim that tree whether or not the guard was there — it now
holds a valid list beside the stray row. And the range question was invisible
until a fixture matched compiled output, as above.

Risk / follow-ups

  • captureLynxFirstTree stays the authority on adoption. A shape the pre-check
    does not claim settles exactly as it does today, having paid for the paint; the
    pre-check can only ever be more conservative than capture, never less.
  • Reusing planLynxListUpdate means allocating a full insert plan — one frozen
    action per row — and discarding it. That is most of the 0.501 ms the list arm
    pays, and it is deliberate: the cheaper option is a local key-uniqueness check,
    which restates the rule this slice exists to avoid restating. 0.5 ms to remove
    33 ms is the right side of that trade.
  • The pre-check is a second reader of the list rules. It calls the same two
    list.ts functions rather than duplicating them, so a rule added there is
    honoured here for free — but a rule added to the prepare walk would need
    mirroring, as the two placement rules already are.
  • A future record-tree node kind that is neither host nor range would be
    treated as a range by both walks. Today the union is exactly those two.
  • The template fixture is hand-written to match verified compiler output rather
    than compiled in-process: the lynx vitest project compiles .tsrx with the
    background renderers, so a main-thread fixture would need a generated-module
    loader, which .rulesync/rules/testing.md rules out. If the main-thread
    lowering changes shape, that fixture goes stale silently.
  • Still unaddressed: the 5.1 ms render that produces the records. Answering
    without rendering at all needs the compiler to declare that a page may hold a
    <list>, which is out of scope for this slice.
  • C2 (teaching adoption to carry lists) is the item that makes this path
    unnecessary rather than cheap.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Huxpro and others added 4 commits August 20, 2026 11:05
A page holding a native `<list>` rendered, built a full command batch, took a
host container, staged and applied it, planned the native list, was refused by
adoption capture, and was torn all the way back out — to reach a verdict that
never depended on any of it having happened. `captureLynxFirstTree` refuses
every root holding a `<list>` outright, and the renderer's record tree already
carries every element type and prop that refusal reads.

`firstScreenTreeIsUnadoptable` asks the question there, before the container
exists, and `renderFirstScreenNow` retires a tree it claims with no container
and no Element PAPI traffic at all. At 1,000 native rows (4,002 logical hosts)
the synchronous first screen goes from a median 37.8 ms and 18 PAPI calls to
5.1 ms and none, with disjoint distributions across four before-passes and
three after-passes of 21 samples. Almost none of the removed cost was host
traffic — an unscrolled native list creates no cells — so those 18 calls stand
for Octane's own batch, prepare, apply, list plan, capture, and teardown behind
them. A list-free page pays only the walk: 0.063 ms median over that same
4,002-host tree, 0.06% of its first screen, with host traffic unchanged.

Skipping a build must never skip a diagnostic, so the pre-check claims a tree
only when the staged path would have accepted it, and establishes that by
running the real validators rather than restating their rules:
`createLynxListItemDescriptor` and `planLynxListUpdate` over the same nodes,
with the prepare walk's nested-`<list>` and `<list-item>`-placement rules
tracked alongside. A host offering no list PAPI is excluded too — a page that
cannot build a `<list>` at all needs that report, not a silent skip.

Ranges are transparent to both walks, which is what makes this fire on real
code: a `<list>` takes its rows from a keyed `@for`, so a range sits between the
list and every `<list-item>` and the rows are not the list's own children. A
reader stopping at the immediate children would validate an empty list, decline,
and swallow every row defect. Both walks are iterative for the same reason their
neighbours are: a range chain is a chain of nested directives, and nothing here
may cap a depth the renderer accepted.

`captureLynxFirstTree` stays the authority on adoption. A shape the pre-check
does not claim settles exactly as it does today, having paid for the paint.

Two existing tests pinned build-then-teardown and were rewritten rather than
deleted: one now asserts no flush ever carried the list or its shell, and the
other — whose always-throwing `__RemoveElement` had become unreachable — now
asserts that a declined first screen has nothing to remove and announces
readiness on the first attempt.

`.changeset/lynx-first-screen-declines-native-list.md` is merged but unreleased
and its last paragraph promised this work while predicting a different route to
it. Left alone it would ship in the same CHANGELOG entry as this change and
contradict it, so it now records the item as closed and by what means.

Refs #66.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
The comment said a `<list-item>` under a range under a `<list>` is "the shape
every list fixture has", which is backwards: the hand-built fixtures nest rows
directly and only the keyed one goes through a range. What matters is that it is
the shape every *authored* list has, since rows come from a keyed `@for` — and
that a reader stopping at the list's immediate children would validate an empty
list, decline, and swallow every row defect.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Every list fixture nested its rows directly under the `<list>`, which no `.tsrx`
produces. Compiling `tests/_fixtures/native-list.lynx.tsrx` with
`lynxMainThreadRenderer` shows the real lowering: `<list id="native-feed">`
becomes a `template` create program rather than a `host` plan node, with its
rows in one child hole as a keyed `@for`, and the record tree it renders is
`host <list>` over one `range` per row, each holding one `host <list-item>`.

Two properties the pre-check depends on, neither previously covered. The
template-created `<list>` still records as an ordinary `list` host. And its rows
are not its own children, so a reader stopping at the immediate children would
validate an empty list, decline, and swallow every row defect — while still
passing a decline test, which is why a decline test alone is not evidence of
this.

Adds a template fixture matching the emitted `kind`/`slots`/`create` shape, and
for both it and the keyed-loop fixture a decline test plus a duplicate-`item-key`
test. Making ranges opaque turns both duplicate tests red and leaves both decline
tests green.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
`pnpm format:check` fails on the stack for three generated JSON results, which
blocks the gate for every branch above them. All three are formatted correctly
on `new-lynx`; the unformatted copies came in with this stack:

- `stages/results/live-1000.json` and `live-10000.json` were rewritten by
  `888d9034f` and `88e9db5f0`, first carried by `perf/lynx-bg-replay-attribution`
  (#102).
- `prototype/results/u0-block-core-counts.json` is new in `781e4fca3`, on
  `test/lynx-u0-block-counts` (#107).

Fixed forward here rather than at the source, because both of those branches are
published and under review and repairing them in place would rewrite history four
and two branches deep. Nothing but whitespace changes: each file reparses to a
byte-identical JSON value.

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

The unadoptable pre-check replayed only the list validators, so a page
holding a valid native <list> plus a defect the prepare walk reports — a
main-thread: event prop colliding with a background listener, or one
main-thread ref descriptor assigned to two visible hosts — settled as a
quiet 'skipped' instead of 'failed' with the error, contradicting the
pre-check's own contract that a skipped build never skips a diagnostic.
Replay both checks over the tree before granting the skip verdict, and
throw the staged path's errors so the screen retires exactly as it does
today. Both regressions verified red first.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
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.

1 participant