Skip to content

perf(lynx): build first-screen host records without spread-and-delete - #109

Merged
Huxpro merged 4 commits into
new-lynxfrom
perf/lynx-first-screen-records
Aug 20, 2026
Merged

Huxpro merged 4 commits into
new-lynxfrom
perf/lynx-first-screen-records

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Stacked on #108 (perf/lynx-first-screen-batch). Third slice of #66 Phase B:
build first-screen host records without spreading and then deleting from the
copy.

hostNode used to do {...rawProps} and then delete key, ref,
children, and every event-named prop off the copy. A delete on a fresh
object moves it to V8 dictionary mode for the rest of its life — and these
objects are not scratch: they are the first screen's props bags, read later by
the direct applier and again by adoption capture. The fixture's 10k rows carry
bindtap on the row and a key on every row, so every row host took that
transition.

The bag is now built by copying only the keys it keeps, in the same pass that
classifies events, so nothing is ever deleted. Two shapes fall out of that:

  • A host that binds no events shares one frozen empty map (NO_FIRST_SCREEN_EVENTS)
    instead of allocating its own — the same shared-empty idiom the host driver
    already uses for props/children/events.
  • Raw #text records get their own constructor. Their props are a string
    value and nothing else — that is exactly what assertTextProps in the host
    driver enforces — so they skip the generic classify loop. Three of every seven
    hosts in ROW_TEMPLATE are #text, so at 10k rows that is 30,000 records off
    the generic path.

One behavioural detail changed and is now covered: an event-named prop whose
value is neither a handler nor the first-screen sentinel used to survive into
the props bag, because the old code only deleted names it had classified as
bound. It is now dropped, which matches what the background renderer does with
the same input.

Why

#66 §4 wants the first screen's intermediate records to stop being the dominant
cost of the direct path. This is the allocation half of that: same record tree,
same consumers, cheaper to build and cheaper to read.

Changes

  • packages/lynx/src/main-renderer.ts
    • hostNode builds props by copy-in rather than spread-and-delete, and
      collects events in the same pass (lazily allocating the map).
    • NO_FIRST_SCREEN_EVENTS: a shared frozen-empty event map for hosts that
      bind nothing.
    • textNode(value) constructs #text records directly; both #text call
      sites use it.
  • packages/lynx/tests/main-renderer.test.ts: a string-valued bindtap is
    dropped from the emitted props, matching background.
  • docs/lynx-specialized-target-l0.md §8: the increment recorded, per Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66 §0.
  • benchmarks/lynx-table/prototype/results/fcp-10000-phase-b.{json,md}: the
    product-boundary A/B below, committed beside the other session records.
  • Changeset (patch, @octanejs/lynx).

Measurements

This slice, phase by phase

FS_COST_ROWS=10000, FS_COST_GC=1, NODE_OPTIONS=--expose-gc. Three
alternated rounds of 10 reps per side, pooled (30 samples/side), before =
0d64af8 (#108 head), after = this branch. Phases are GC-isolated so a build's
own garbage is not billed to the next phase.

phase before min / p25 / med after min / p25 / med Δ min Δ med
render (builds records) 139.0 / 150.5 / 163.3 79.3 / 104.6 / 116.7 −42.9% −28.5%
capture (adoption) 218.1 / 234.4 / 252.6 214.3 / 239.9 / 258.5 −1.7% +2.3%
apply (direct PAPI) 429.1 / 473.9 / 493.8 407.1 / 464.1 / 500.7 −5.1% +1.4%
batch (staged path only) 55.4 / 63.6 / 67.8 45.1 / 53.4 / 57.1 −18.6% −15.8%
direct path (render+capture+apply) 794.6 / 872.9 / 934.6 731.8 / 800.2 / 876.7 −7.9% −6.2%

Render is the phase this slice touches and it moves in every round
individually (171.8→123.4, 151.1→110.1, 167.6→120.8 ms median). Apply and
capture sit inside noise in both directions across rounds, which is the
expected result — the applier is untouched. The batch phase gets a smaller
real win it did not ask for: buildFirstScreenBatch reads back the same props
bags, and reading a fast-mode object is cheaper than reading a dictionary-mode
one.

The whole Phase B stack at the product boundary (#66 §4 bullet 4)

The app built at 781e4fca3 (the stack base, #107's head) and at this head,
driven through prototype/run-fcp.mjs in one window, cells alternating AB/BA,
fresh page per sample. 4× Xeon @ 2.80 GHz, load 0.49 at start, n=30 per cell.

cell median FCP min–max
octane-baseline — stack base 2751.6 ms 2519.4–3098.2
octane — this head 2599.1 ms 2307.2–2783.0
octane-direct — L0 direct-emission floor 1534.0 ms 1407.2–1898.6

Cells alternate inside one window, so each rep is a matched pair: paired mean
difference −158.5 ms (sd 175.8), t(29) = −4.94, 95% CI [−224.2,
−92.9] ms
, head faster in 22 of 30 reps, median ratio 0.947×. That is
~12.6% of the distance from the base to the floor the same window measures.

n=15 could not tell the two apart and is reported for that reason: −113.6 ms
with a 261.8 ms paired spread, t = −1.68, head faster in 10 of 15. A single page
load at this boundary varies by more than the whole effect. The number is only
reportable because n=30 resolves it.

Validation

  • pnpm sync clean (no generated changes)
  • pnpm format:check
  • pnpm format:files on changed files
  • pnpm typecheck
  • pnpm typecheck:files packages/lynx/src/main-renderer.ts
  • pnpm test — full run at 935d6e3d: 2182/2196 files, 20,954 tests
    passing
    . No packages/lynx or packages/octane failure; all 14
    failures are timeouts or browser/process flakes on a loaded host. Detail
    and per-package attribution in a comment below.
  • targeted: --project lynx, --project octane, --project octane-prod

Note on scope: packages/lynx/tsconfig.json excludes tests, so the repo-wide
pnpm typecheck does not cover lynx test files; main-renderer.test.ts has
pre-existing useEffect arity errors under typecheck:files that are present
on the unmodified file too.

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

`hostNode` copied its incoming props with a spread and then deleted `key`,
`ref`, `children`, and every event-named prop off the copy. `delete` on a
fresh object drops it out of V8's fast properties for the rest of its life,
and these objects are long-lived: the direct applier reads them, and so does
adoption capture. The scan for event props then walked the copy a second
time, and an event map was allocated for every host whether or not it bound
anything.

The bag is now built by copying only the keys it keeps, in one pass that
also collects the events, and a host that binds nothing shares one read-only
empty map. Behaviour is unchanged, including the part nothing checked: an
event-named prop carrying something that is not callable leaves the props bag
without becoming a listener, exactly as the spread-and-delete did. That now
has a test, because the background does the same and a first screen that
disagreed would lose adoption for the whole page.

Raw `#text` records skip the generic path. Their props are a string `value`
and nothing else — the shape `assertTextProps` enforces and `create` already
shortcuts — so walking that one-key literal for props it cannot contain, and
allocating an event map that stays empty, was pure overhead. Three of every
seven hosts in the benchmark fixture are one of these.

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

Huxpro commented Aug 20, 2026

Copy link
Copy Markdown
Owner Author

pnpm test at this head — no failure belongs to this diff

One full run at 935d6e3d, which contains #107 and #108, so this covers the
whole stack:

Test Files  14 failed | 2182 passed (2196)
     Tests   8 failed | 20954 passed | 75 skipped (21037)
  Duration  3782.40s

No packages/lynx test failed, and no packages/octane test failed —
including lynx-target-first-screen.test.ts, the four-cell differential that
0d64af8 fixed after the first pass missed it. The targeted run behind that fix
(--project lynx --project octane --project octane-prod) had already come back
872 files / 12,863 tests passing.

Every one of the 14 is a timeout or a process/browser flake on a loaded host —
the run overlapped several Playwright suites on 4 CPUs, with load average
sitting at 4–6 throughout:

failure reason
aria hydration, aria package-boundary, alien-signals hydration, octane react-hosted/web3-island Hook timed out in 10000ms in a beforeAll that SSR-renders or bundles a fixture
adapter-vercel adapt, dropzone hydration, syntax-highlighter negative-controls Test timed out in 5000ms
docusaurus hydration Test timed out in 15000ms
website ssr-hydration (dev + preview), website ssr-smoke, doom production, octane browser suspense-hydration, drei browser e2e real-browser suites
rspeedy-plugin native-demo escalates cleanup for a detached descendant after its leader exits — the failure #66 §2.3 records as pre-existing in this container

The attribution is not just by symptom. This stack changes three files in
packages/lynx/src plus lynx tests, one packages/octane test, a changeset and
a doc. Of the failing packages, exactly one depends on @octanejs/lynx —
rspeedy-plugin-octane — and its failing assertion is about killing a detached
process tree, which no renderer change reaches. The other twelve
(adapter-vercel, docusaurus, drei, dropzone, syntax-highlighter,
aria, alien-signals, website, playground/octane) have no lynx
dependency at all.

web3-island was separately A/B-verified earlier in this session: it passes
standalone at both the stack base and this head, and only fails inside a full
concurrent run.


Generated by Claude Code

The three first-screen slices were measured phase by phase in a Node harness.
This is the same change at the product boundary: the app built at the stack
base and at its head, driven through prototype/run-fcp.mjs in one window,
cells alternating, fresh page per sample.

n=15 could not tell the two apart — the paired difference was -113.6 ms with
a 261.8 ms spread, t=-1.68. n=30 resolves it: -158.5 ms paired mean, 95% CI
[-224.2, -92.9], t(29)=-4.94, head faster in 22 of 30 paired reps. Median
FCP falls 2751.6 -> 2599.1 ms, which is 12% of the distance from the stack
base to the direct-emission floor the same window measures at 1534.0 ms.

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

Huxpro commented Aug 20, 2026

Copy link
Copy Markdown
Owner Author

#66 §4 bullet 4 — FCP@10k at the product boundary, whole stack vs its base

The three slices were measured phase by phase in a Node harness. This is the
same change measured where the user experiences it: the benchmark app built at
781e4fca3 (the stack base, PR #107's head) and at this branch's head, driven
through benchmarks/lynx-table/prototype/run-fcp.mjs in one window, cells
alternating AB/BA, fresh page per sample. Record committed at
prototype/results/fcp-10000-phase-b.{json,md}.

Host: 4× Xeon @ 2.80 GHz, load 0.49 at start, Node v22.22.2. n=30 per cell.

cell median FCP min–max
octane-baseline — stack base 2751.6 ms 2519.4–3098.2
octane — this head 2599.1 ms 2307.2–2783.0
octane-direct — L0 direct-emission floor 1534.0 ms 1407.2–1898.6

Cells alternate inside one window, so each rep is a matched pair:

  • paired mean difference −158.5 ms, sd 175.8
  • t(29) = −4.94, 95% CI [−224.2, −92.9] ms
  • head faster in 22 of 30 paired reps
  • median ratio 0.947×

n=15 was not enough and said so. The first run gave −113.6 ms with a
261.8 ms paired spread, t = −1.68 — head faster in 10 of 15, ranges overlapping
end to end. At this boundary a single page load varies by more than the whole
effect, so the honest reading at n=15 was "cannot tell", and the number is only
reportable because n=30 resolves it. Recording that here because the n=15 table
would have been easy to publish as a −4% win.

What it is worth against the roadmap. #66 §4 wants the first screen moved
toward the architecture floor #59 established. In this window the base sits
1213.5 ms above that floor; the stack removes 152.5 ms of it, so it closes
~12.6% of the distance to the floor — consistent with the phase harness,
which attributes the change to render, capture, and apply while leaving the
transport, the platform's own element creation, and the frame boundary
untouched. Those are the rest of the 1213.5 ms and they are what Phase C and
#103 are aimed at.

The direct/octane ratio the harness prints is 0.590× here against 0.575×
in the record #59 committed on a different host — the same architectural gap,
reproduced independently, which is the part of this that is comparable across
sessions. Absolute ms are not: this host renders the same page ~1.7× slower than
the one #59 used.


Generated by Claude Code

Huxpro added a commit that referenced this pull request Aug 20, 2026
The cutover-gate report named #109's record-shape change as the hypothesis to
test first for the few-percent excess on create, update10th, and updateStorm.
Reading the stack's source diff retires it.

The stack edits nine source files. block-core.ts and block-root.ts are new and
behind a per-root flag. delta-protocol.ts and delta-shadow.ts are profiling-only,
constructed under LYNX_PROFILE. main-renderer.ts and core/first-screen.ts are
first-screen render. main-thread.ts is the direct-applier call site. Every
host-driver.ts hunk lands in applyLynxFirstScreenDirect, captureLynxFirstTree,
compareFirstTree, transferFirstTree, the native-list constructors, or the
once-per-root firstTreeAction === 'adopt' branch of prepareLynxHostBatch. The
compiler flips one slot kind from 'c' to 'r', and slots is read only by
main-renderer.ts, which validates and copies it and branches on neither value.

Nothing a mutation cell executes after adoption was edited, so a logic
regression on that path is ruled out. Two candidates remain and neither is
claimed: the bigger main-thread bundle every cell runs inside (+4,202 B raw,
+1,721 B gzip), and slow host drift across the session, which AB/BA alternation
does not control because it only controls ordering within a window. The first is
directly testable by padding the base bundle with dead bytes to the head's size
and re-running the sweep.

Records the file-by-file table so the next session can check the reasoning
rather than repeat the elimination.
@Huxpro
Huxpro changed the base branch from perf/lynx-first-screen-batch to new-lynx August 20, 2026 19:57
@Huxpro
Huxpro marked this pull request as ready for review August 20, 2026 19:57
@Huxpro
Huxpro merged commit 7882d44 into new-lynx Aug 20, 2026
1 of 2 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.

2 participants