Repository navigation
fix(lynx): walk the direct first screen with an explicit stack (#90) - #93
Merged
Merged
Conversation
`applyLynxFirstScreenDirect` recursed once per tree level, and `firstScreenTreeHasList` — which runs on the same tree immediately before it — recursed too. The staged path they replaced walks a flat command array and consumes no frames, so issue-58 L3 made the first screen the only stack-bound stage in the pipeline, binding before `renderLynxFirstScreen`'s own recursion. Trees the renderer produces, the applier then refused with `RangeError` (#90). Both are explicit work stacks now. A frame carrying a papiNode instead of a node is the deferred attach, queued before the node's children so it pops after them; children are pushed reversed so siblings pop in authored order. #90 attributes the throw to `visit`. The first frame to blow is actually the list predicate, which runs earlier and is cheaper per frame; fixing only the applier leaves the ceiling in place. Both halves are separately load-bearing and the regression test shows it. The existing snapshot, event-journal, and physical-tree differentials all compare finished state, so a top-down attach builds the identical tree and passes every one of them — verified by deliberately reordering the attach and watching the suite stay green. The walk's own properties are therefore pinned directly: a test records the attach sequence through the PAPI and asserts each host is attached only after its whole subtree is, with roots and siblings in authored order. Reordering the attach, reversing roots, reversing siblings, and reverting the predicate to recursion each turn it red. The depth regression builds its tree iteratively and hands it straight to the applier, so the depth under test is the applier's own rather than the renderer's or the test file's. Same-window mount-create FCP@10000, fresh page per sample, AB/BA, n=5, quiet host: recursive 1694.6 ms (1464.6-1728.1) versus iterative 1557.1 ms (1510.2-1725.2), architecture floor 1038.0 ms. The ranges overlap across almost their whole width, so this is a no-regression result and not a speedup: it establishes that one frame object per node costs nothing measurable. Raw bundle grows 506 B on 489 KB. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
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
applyLynxFirstScreenDirectwalked the rendered tree with a recursivevisitclosure, and
firstScreenTreeHasList— which runs on the same tree immediatelybefore it — recursed too. Each consumes a call frame per tree level. The staged
path they replaced walks a flat command array and consumes none, so #65 made the
first screen the only stack-bound stage in the pipeline, and it binds before
renderLynxFirstScreen's own recursion does. Trees the renderer can produce, theapplier then refuses with
RangeError.Both are explicit work stacks now. Reported as #90.
Why
This is a regression the stack introduced:
applyLynxFirstScreenDirectdoes notexist at
6079a6804, where the first screen goes throughprepareLynxHostBatchonly. #90 measured base painting host depth 4200 where the stack throws — about
a thousand levels the renderer can produce and the applier cannot paint.
The absolute crossover is engine-dependent and was measured on V8. The
direction is not: one frame per level versus zero. PrimJS's stack budget is
typically smaller than V8's, which moves the crossover down rather than up. That
remains the open question #90 names, and it needs a device to answer.
One correction to #90's diagnosis. It attributes the throw to
visit. Thefirst frame to blow is actually
firstScreenTreeHasList, which runs earlier andis cheaper per frame, so it survives deeper but still binds first. Fixing only
the applier leaves the ceiling in place. Both halves are separately load-bearing,
and this PR demonstrates that: with the predicate made iterative and
visitleftrecursive, the regression test still fails, now inside
visit.Changes
packages/lynx/src/core/host-driver.tsfirstScreenTreeHasList: iterative over pending child lists.applyLynxFirstScreenDirect:visittakes a frame from an explicit stack.A frame carrying a
papiNodeinstead of anodeis the deferred attach,queued before the node's children so it pops after them; children are
pushed reversed so siblings pop in authored order.
packages/lynx/tests/first-screen-direct.test.ts: two regressions.docs/lynx-specialized-target-l0.md§8, and the committed FCP session record.Validation
The existing differentials do not cover the walk order, and I found that by
trying to break it. The snapshot, event-journal, and physical-tree assertions
in this file all compare finished state, so a top-down attach — publishing an
empty node into the live page and filling it afterwards — builds the identical
final tree and passes every one of them. Deliberately reordering the attach kept
the suite green, as did reversing root order (the existing scene has one root).
Only sibling reversal was caught.
So the walk's own properties are pinned directly, by a test that records the
attach sequence through the PAPI and asserts every host is attached only after
its whole subtree is:
firstScreenTreeHasListreverted to recursionThe depth regression builds its node tree iteratively and hands it straight
to
applyLynxFirstScreenDirectwith a synthesized batch, so the depth under testis the applier's own — not the renderer's, and not the test file's. That is what
keeps the assertion independent of the host's stack size instead of pinned to
whatever ceiling one machine happens to have. Red before the fix with
RangeErrorathost-driver.ts:2884; green after.Separately, before touching the file, the rewrite was checked against the
recursion offline over 400 randomized trees (mixed host/range nodes, varied
fan-out and depth): identical operation journal and identical record-children
assembly, 27,874 journal lines compared.
pnpm typecheckpnpm sync(no generated changes)pnpm format:fileson every changed pathpnpm vitest run --project lynx --project octane --project octane-prod—866 files / 12,796 tests passed
pnpm vitest run --project rspeedy-plugin— 63 passed, 1 failed: thenative-demo"escalates cleanup for a detached descendant" case issue Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66§2 already names as pre-existing in this container, and which reproduces on
the base commit
pnpm testrepo-wide (run on the parent PR perf(lynx): classify host updates without building the prop patch (issue-66 A4) #92, where the only failureswere five browser cases that reproduce identically on the base commit)
Measurement
Mount-create FCP@10000, same window, fresh page per sample, cells alternating
AB/BA, n=5, quiet host (1-minute load 0.34 on 4 logical CPUs).
baseis apreserved pre-change build of the same app; committed as
benchmarks/lynx-table/prototype/results/fcp-10000-depth-fix.md.octane-direct(L0 architecture floor)This is a no-regression result, not a speedup. The medians favour the
candidate at 0.919×, but the ranges overlap across almost their whole width and
n=5 cannot separate them; nothing here supports a claim that replacing call
frames with heap frames made the first screen faster. What it does support is
that one frame object per node did not cost anything measurable, which is the
question this change had to answer.
Raw bundle: 489,384 B versus 488,878 B, +506 B (+0.1%) on the app's
main.web.bundle.Risk / follow-ups
main-thread.ts:1906falls back to the staged path only on a
falsereturn, so a throw retiresthe first screen instead of repainting through the path that would have
succeeded. Extending the fallback to catch a throw is not the one-line
change the issue suggests: the direct applier mutates as it walks, so a
mid-walk throw leaves partially-painted PAPI state, marks the container
faulted, and invalidates main-thread lifetimes. Replaying the staged path onto
that container would paint on top of the partial tree. A real fallback needs
the applier to be transactional — a separate slice, and the same prerequisite
Direct first-screen applier skips the main-thread/background event collision check, silently dropping the main-thread handler #84's "refuse before mutating" needs.
is what justifies that choice; if a device measurement later says otherwise,
the frame fields become parallel arrays without changing the walk.
Provenance
agent-authored)Generated by Claude Code