Repository navigation
perf(lynx): take first-tree capture off the first-paint path - #751
Merged
trueadm merged 3 commits intoAug 13, 2026
Merged
Conversation
…nership First-tree capture re-plans every painted host's props, but only to recover what the main thread should own: a `main-thread:` event handler or `main-thread:ref`. Those are the only two ways to declare it and both carry the `main-thread:` prefix, so a host without one can be answered by a prop-name test rather than a full patch plan. The props themselves were already planned and applied when the tree was built; this call rediscovers nothing else. The surrounding checks are unchanged, including the one that matters when the plan is skipped: a host that never asked for main-thread ownership must still have none mounted. This sits on the first-paint path. Capture runs after the page is published to the host, so every millisecond it spends is paint delay — the host-boundary instrument in benchmarks/lynx-table measures that window at 16.7-20.1% of FCP across 1k/10k/30k rows. In the benchmark's 10,000-row first screen no host declares a `main-thread:` prop, so all 70,041 skip planning and the capture-time planning cost falls from a 58.3 ms median to 28.8 ms on the same instrument. End to end that is about 1.7% of first paint, below what the harness resolves on a 4-CPU host, so no wall-clock claim is made for it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UMisRkW6cGfodXwpy4kxYS
Capturing the first tree runs after the page is already published to the host, so everything it does sits between the tree reaching the DOM and the browser painting it. The host-boundary instrument measures that window at 16.7-20.1% of FCP across 1k/10k/30k rows. Most of it is not validation, it is allocation: turning the captured tree into the clone-safe description the background clones when it adopts. Nothing before adoption reads that description, so it now builds on first read. What stays eager is what the contracts need: - validation and the native-ID read, because a host that cannot be captured has to fault the synchronous first screen while its caller still holds the source to retry cleanup against; and - the event token map, because a tap on the painted tree resolves through it long before the background adopts. The description therefore reads only retained record fields, which is why `firstScreenSnapshot()` still answers while unmount cleanup retries rather than describing a container mid-teardown. Measured on the lynx-table 10,000-row first screen, paired A/B with both bundles built side by side and alternating order, n=8: the post-publication window falls from a 217 ms median to 163 ms with every pair improving, and FCP@10k from 1,576 ms to 1,483 ms (paired median -85 ms). Deliberately breaking the description turns 14 tests red across first-screen, host-driver, and milestone-8-integration, so both read orders — first read at adoption, and first read from the public accessor before it — are already covered. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UMisRkW6cGfodXwpy4kxYS
trueadm
marked this pull request as ready for review
August 13, 2026 20:13
1 task done
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
Capturing the Lynx first tree runs after the page is already published to the
host, so everything it does sits between the tree reaching the DOM and the
browser painting it.
Two commits take work out of that window without changing behaviour.
1. Skip prop-patch planning for hosts that own nothing on the main thread.
Capture re-plans every painted host's props only to recover what the main thread
should own: a
main-thread:event handler ormain-thread:ref. Both are theonly ways to declare it and both carry that prefix, so a host without one is
answerable by a prop-name test rather than a full patch plan — and the props
themselves were already planned and applied when the tree was built. The
surrounding checks are untouched, including the one that matters when planning
is skipped: a host that never asked for main-thread ownership must still have
none mounted.
2. Describe the first tree after the paint, not before it. Most of the
window is not validation but allocation — turning the captured tree into the
clone-safe description the background clones when it adopts. Nothing before
adoption reads it, so it now builds on first read. Capture splits along
validation-versus-allocation rather than eager-versus-lazy, which is what keeps
the contracts intact:
cannot be captured must still fault the synchronous first screen while its
caller holds the source to retry cleanup against; plus the event token map,
because a tap on the painted tree resolves through it long before adoption;
retains, so
firstScreenSnapshot()still answers while unmount cleanupretries.
Relationship to #748–#750
against the tip of that stack (
555f491d). Both merges completedautomatically; the shared
host-driver.tshunks do not overlap.acknowledgement, handle-generation, and teardown paths; they do not change
captureLynxFirstTree,snapshotFirstTreeProps,firstScreenSnapshot, or first-screen adoption. This PR changes thecapture/description and main-thread-prop ownership path specifically.
floor. Its 99.0% factory and 84.7% apply floors are work before publication;
this PR removes framework allocation between flush #0 ending and flush Add changeset for the vyre→octane rename release #1
starting. The two investigations agree that publication op count and flush
batching are NO-GO levers.
not required for correctness, but if that stack lands first the absolute
217 ms baseline from the original fork PR is stale and must be re-measured on
top of it.
Measurements
Re-measured independently on current upstream
main(ecc7700b) with thefork-only #52 Element PAPI harness. The harness was cherry-picked only into a
scratch branch and is not part of this PR.
sampling
996039633, twoflushes
Commit 1 resolves positive on this quieter host, so both commits remain in the
PR. The sensitive post-publication metric is flush #0 end → flush #1 start.
The measurement used the harness's counts probe, which retains exact flush
start/end epochs without adding a clock read to every Element PAPI call.
Validation
packages/lynxsuite on the exact fork head: 25 files, 340/340 passed.main+ this PR:packages/lynx340/340 passed.integration: 3/3 passed, including native tap, gallery scrolling, and a
main-thread handler flush.
pnpm test -- --silent=passed-only: 2,179/2,181 files and20,916/20,921 tests passed. The five failures were fixed-5-second timeouts in
unrelated CLI and website-MCP suites under the full 276-workspace run; the
two affected files then passed 17/17 when rerun together (slowest 1.28 s).
No browser project failed.
hasLynxMainThreadPropto always returnfalse makes
transfers a compatible first tree without allocating or restructuring native nodesfail.failures across
first-screen,host-driver, andmilestone-8-integration.direction with identical semantic checksums.
pnpm typecheck:fileson the three changed source files.pnpm format:files:checkon all five changed files.Risk / follow-ups
packages/lynxcore. Behaviouris meant to be identical. Commit 1's precondition is exact because
main-thread:refandparseLynxMainThreadEventPropboth require thatprefix and nothing else declares main-thread ownership. Commit 2's deferred
description reads only record fields teardown retains.
using these absolute numbers; perf: re-arm compact acknowledgements after certified teardown #749/perf: tear down removed collapsed runs with one destroy-run command #750 change warmed protocol timing even
though they do not enter this capture path.
Provenance
agent-authored)Generated by Claude Code
Note
Medium Risk
Touches first-screen capture and adoption contracts in core Lynx; behavior is intended to be identical but timing and memory retention paths change around snapshot build and release.
Overview
Moves work out of the post-publication, pre-paint window for Lynx first-tree capture without changing observable behavior.
During capture, hosts that have no
main-thread:props no longer run a fullplanLynxHostPropPatchpass;hasLynxMainThreadPropgates planning while the same main-thread event/ref consistency checks still run (using a shared empty event list when planning is skipped).The clone-safe first-tree snapshot is no longer built synchronously at the end of capture. Capture still validates structure, native IDs, and event tokens eagerly, but
createLynxFirstTreenow takes adescribecallback and exposessnapshotvia a getter that materializes once on first read.releaseLynxFirstTreeclearsdescribeso released trees do not retain the source container.Two patch changesets document benchmark impact on large first screens (e.g.
lynx-table@ 10k rows).Reviewed by Cursor Bugbot for commit 79ec1b7. Bugbot is set up for automated code reviews on this repo. Configure here.