Skip to content

fix(lynx): walk the direct first screen with an explicit stack (#90) - #93

Merged
Huxpro merged 1 commit into
new-lynxfrom
fix/lynx-first-screen-depth
Aug 19, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
fix/lynx-first-screen-depth

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Summary

applyLynxFirstScreenDirect walked the rendered tree with a recursive visit
closure, and firstScreenTreeHasList — which runs on the same tree immediately
before 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, the
applier then refuses with RangeError.

Both are explicit work stacks now. Reported as #90.

Why

This is a regression the stack introduced: applyLynxFirstScreenDirect does not
exist at 6079a6804, where the first screen goes through prepareLynxHostBatch
only. #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. The
first frame to blow is actually firstScreenTreeHasList, which runs earlier and
is 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 visit left
recursive, the regression test still fails, now inside visit.

Changes

  • packages/lynx/src/core/host-driver.ts
    • firstScreenTreeHasList: iterative over pending child lists.
    • applyLynxFirstScreenDirect: visit takes a frame from an explicit stack.
      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.
  • 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:

deliberate break before this PR's test with it
attach queued after children (top-down attach) 6 passed 1 failed / 5 passed
children pushed forward (siblings reversed) 1 failed / 5 passed 2 failed / 4 passed
roots pushed forward (root order reversed) 6 passed 1 failed / 5 passed
firstScreenTreeHasList reverted to recursion — 1 failed / 5 passed
(restored) — 6 passed

The depth regression builds its node tree iteratively and hands it straight
to applyLynxFirstScreenDirect with a synthesized batch, so the depth under test
is 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
RangeError at host-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.

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). base is a
preserved pre-change build of the same app; committed as
benchmarks/lynx-table/prototype/results/fcp-10000-depth-fix.md.

cell median ms min–max
base (recursive) 1694.6 1464.6–1728.1
candidate (iterative) 1557.1 1510.2–1725.2
octane-direct (L0 architecture floor) 1038.0 952.9–1242.7

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

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

`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
@Huxpro
Huxpro changed the base branch from perf/lynx-host-prop-classify to new-lynx August 19, 2026 18:30
@Huxpro
Huxpro marked this pull request as ready for review August 19, 2026 18:30
@Huxpro
Huxpro merged commit 3998d4a into new-lynx Aug 19, 2026
3 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.

1 participant