Repository navigation
perf(lynx): adopt the first screen's props instead of copying them - #271
Merged
Merged
Conversation
`cloneProps` exists because a host prop bag normally arrives from the other thread, a separate JS realm in production, so the container has to build data it owns out of values it has proved it can hold. The direct first-screen path has no such crossing: its bag was built by `universalProps` in this realm, on this call stack, and frozen at its only construction site. When every value is a scalar there is nothing to clone and no tagged callable to unwrap, so the container holds the bag it was given. Adoption tests each of those rather than assuming them, and a bag that fails any one takes the copy: still mutable, reached through a class, or holding an object. The prototype test asks for this realm's `Object.prototype` or none, not the copy's looser cross-realm shape, because a prototype one hop from null can carry enumerable properties of its own that `for...in` over a stored bag would see. The `main-thread:` unwrap is now asked of a value rather than of a name. A tagged callable is a function, so it can only appear where the copy already stops for a non-scalar; the pass it replaces walked every key of every bag, and on a 60,002-host page found nothing. Publish at 10,000 rows falls from a 475.5 ms median-of-medians to 337.9 ms over an interleaved four-round A/B, with the arms' medians not overlapping. Refs #247. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Huxpro
changed the base branch from
perf/lynx-lazy-first-screen-handle
to
new-lynx
September 2, 2026 07:53
Huxpro
marked this pull request as ready for review
September 2, 2026 07:53
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
The second cut of #247's publish work, and the larger half of the record-building
bucket #270 opened on. Per the owner directive (#247 issuecomment-5485061147):
drive the compiled/direct path through
publishuntil the interpreted remainderis gone, using #254's phase segmentation as a local build tool rather than a
merge gate.
clonePropsis 27.7 ms of #247's 83.2 ms host-record bucket at 10,000 rows, andthis PR stops calling it on the direct first-screen path.
The copy is defending against a boundary this path does not have
clonePropsexists because a host prop bag normally arrives from the otherthread — a separate JS realm in production — so the container must build data it
owns out of values it has proved it can hold. The direct first-screen path has no
such crossing. Its bag was built by
universalProps(
packages/octane/src/universal-core.ts) in this realm, on this call stack, andfrozen at its only construction site: both of that function's return paths end
in
Object.freeze(props), so frozen-on-arrival is a construction invariant ratherthan a property of one fixture.
__proto__is installed there as an own dataproperty by
defineUniversalProtoProp, so the prototype is always this realm'sObject.prototype.So the container can hold the bag it was given, and
adoptFirstScreenPropsdoes —after testing each premise instead of assuming it. A bag that fails any one takes
the copy exactly as before: still mutable, reached through a class, or holding an
object.
The counters chose the shape before the code was written
The copy's work at 10,000 rows, from a local instrument (60,002 bags, 70,002 keys):
Every bag is already frozen, every bag is scalar-only, and not one carries a
main-thread:key. For a scalar-only frozen bag the copy's only observableproduct is the null prototype — which is what made adoption, rather than a faster
copy, the shape of the cut. Per #264 this is structural and not a cache: that
census settled the memo question (identity-keyed hit rate 0.0000 over 40,028
nodes; value-keyed declined) and is not revisited here.
The
main-thread:unwrap now asks a value, not a nameclonePropsran a whole pre-pass — a{...source}spread plus astartsWithperkey — to find tagged callables. A tagged callable is a function, so it can only
appear where the copy already stops for a non-scalar. Folding the unwrap into that
branch costs one
startsWithper non-scalar prop instead of one per prop, and afirst screen of scalar bags never asks it at all. The pass this replaces walked
70,002 keys to find zero.
Changes
@octanejs/lynx:adoptFirstScreenProps, wired into the single directfirst-screen call site;
clonePropsfolds itsmain-thread:pre-pass into thecopy loop's non-scalar branch. The wire paths — create, update, recreate,
template-run and program-plan — all keep
clonePropsunchanged.Correctness
The gate the directive keeps in full force is byte-identity between the old and
new publish path, plus a decline path for anything the direct path cannot carry.
Four new tests in
first-screen-direct.test.ts, on a scene whose prop names areObject.prototypemembers (constructor,toString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString) withan unadoptable nested-
stylechild beside them:applyLynxFirstScreenDirectand the staged
prepareLynxHostBatch;after painting and asserts the snapshot is unaffected;
(
/host props require plain objects/);Each assertion was falsified before being trusted, per
octane-core-extend:lynxtestsObject.isFrozentestmain-thread:unwrapcloneProps's cross-realm shapeThe fifth is reported as a miss rather than dressed up. I traced it: both
for…inreaders of a stored bag operate on compiled-program prop tables rather than on
adopted first-screen bags, so no existing scene can observe an inherited
enumerable today. The tightening is defensive — it was found by reading rather
than by measuring, and it closes the hazard before a future reader opens it, but
this suite would stay green without it.
A deliberate strictness change
The deleted pre-pass built
{...source}before the prototype test ran, whichlaundered a non-plain prototype through the spread. A class instance carrying a
main-thread:handler was therefore accepted by the oldclonePropsand isrejected by the new one. This is the intended behaviour —
cloneProps's contracthas always been "plain objects only" — but it is a behaviour change on the wire
path, not only on the first screen, and it is called out here rather than buried.
Measurement
Unlike #270, the web lane can resolve this one. An interleaved 4-round A/B
(10,000 rows, 60,002 described hosts, 9 reps/round, arms alternating within each
round):
publishpublishMedian-of-medians 475.5 → 337.9 ms (−137.6, −28.9%); best-min 334.7 → 263.4;
4 of 4 rounds favour the candidate, and the two arms' median ranges do not
overlap ([422.5, 507.9] against [306.3, 377.8]).
Piecewise ablation, and a caveat about it
Sizing, from single-run probes over the same tree (median
publish,[min]inbrackets; these are correctness-breaking probes, not candidates):
main-thread:pre-passRead the ordering, not the numbers. A single run of each arm is not a
measurement, and this campaign has a case that proves it: the
main-thread:pre-pass shows −112.3 ms here and −11.5 ms — inside the noise — when the
same change is run under the interleaved A/B above. The pre-pass fold ships in
this diff on the structural argument alone (70,002
startsWithcalls and 60,002spreads removed to find nothing), not on that −112.3. Only the interleaved figure
in the previous section is claimed as a result. (The same caveat applies to
#270's ablation table, and has been added there.)
Spec-silent choices, noted rather than asked about
this realm's
Object.prototypeor none. The two are answering differentquestions:
hasCrossRealmPlainPrototypedecides whether a bag from anotherrealm is plain enough to copy out of, and accepts "one hop from null" — which
permits a prototype carrying its own enumerable properties. Adoption decides
whether a bag can be held as it is, and
for…inover a held bag would seethose. This realm's
Object.prototypecannot carry them; its members are allnon-enumerable.
Object.keys, notfor…in, for the same reason —the scan must not itself depend on the prototype being clean.
EMPTY_HOST_PROPS. Adoption wouldotherwise hand back a distinct frozen empty object per propless host, and the
shared singleton is the invariant the rest of the driver was written against.
cloneProps, because for those the realm boundary is real.Validation
pnpm typecheck— clean, repo-wide--project lynx— 49 files, 771 tests, all passpnpm test— 4 failed, 26,811 passed, 4 skipped across 2,452 files, with6 files red. None is in
lynx, none can reach the lynx host driver, and eachis accounted for:
suspense-hydration›restores focused input and its selected text after a keyed DOM reorderc124594c7with this stack absent (recorded on #269)drei›should match previous onewaitForFunctiontimeout; samenative-demo›escalates cleanup for a detached descendant after its leader exitssyntax-highlighter›fails closed for missing, extra, renamed, collided, stale, and removed-lane evidenceTest timed out in 5000msexecFileSyncchild processes inside one 5 s deadline. Re-run alone on this head: passes, 4.65 s of test time — it is at the edge unloaded and tips over under the full suitepackages/aria/tests/hydration.test.tsbeforeAlltimeout, its test skippedhookTimeoutunder load. Re-run alone on this head: passes, 19.17 s wallpackages/octane/tests/react-hosted/web3-island.test.ts(octane,octane-prod)beforeAlltimeout, its tests skippedc124594c7with this stack absentThe last two rows are
beforeAllfixture builds hitting the default 10 shookTimeout, which is why 6 files are red but only 4 tests failed: their testsare skipped rather than run.
pnpm format:fileson every changed pathpnpm sync— no generated changesNo cost assertion is added to a correctness test: exact allocation counts are an
optimization claim and belong in the benchmark ratio system, per
octane-core-extend.Risk / follow-ups
first screen. A class instance carrying a
main-thread:prop now throws whereit used to be laundered through the spread.
perf/lynx-lazy-first-screen-handle). The twoare independent in
host-driver.ts— that file auto-merges ontonew-lynx—but both add tests to
first-screen-direct.test.tsat adjacent points, so asolo cherry-pick conflicts there textually. Stacking gives the cleaner review
diff, and GitHub retargets this to
new-lynxwhen perf(lynx): mint a first-screen host handle on demand #270 merges.claude/octane-issue-66-phase-a-7wz97z;this repo's
create-a-prrequires a type-prefixed topic branch so the label botcan read the type from it. The topic branch is used, and the deviation is
flagged here rather than resolved unilaterally.
The next cut was built, and then declined
Recorded here rather than left as a to-do, because the interesting part is why it
did not land. After this PR, a re-profile of
publishon this head namedfirstScreenTreeHasList— a full read-only traversal of every node whose entireproduct is one boolean — at 72.1 ms over 7 screens, 10.3 ms per screen. Fusing
it into the ref/ceiling pre-walk that already visits the same nodes in the same
order was implemented in full: the scan deleted, the list question asked at the
first list host the pre-walk meets, and every pre-walk refusal held rather than
thrown so an unbuildable list still outranks it. It passed 773
lynxtests, andall five deliberate breaks went red — including the two ordering ones that had no
coverage before it (
walk truncated where a refusal is held,held refusal overwritten by a later one).It was declined on its own evidence:
publishpublishMedian-of-medians 310.1 → 333.7, best-min 242.5 → 255.6, three of four rounds
favouring base, arms fully overlapping: a non-result that, if anything, leans
the wrong way. Reading the code back explains it — the deleted scan's comparisons
do not disappear, they move into the fused loop, so what is actually removed is
one loop's iteration and stack overhead, not the per-node work. A cut that
relocates work rather than removing it does not earn the ordering change it
needed (the list decline would have moved to after envelope validation), so it
is not in this diff.
The cut after it landed instead
planLynxHostPropPatch— the next-largest contained frame inpublish, at120.6 ms over 7 screens — turned out to be diffing every first-screen host
against an empty bag it derived seven constants from, 40,002 times per screen.
That one removes work rather than relocating it, and is open as #272, stacked
on this branch. The remaining candidate, the per-host
state.generations.set(id, 1),is sized but carries an
incrementalCompactbehaviour trade and is inside thenoise (321.9 against a 315.7 base); it belongs to the device round, which is where
the directive puts the performance verdict.
Does this change the sequence?
No. This is B under the #247 directive, taken after A (#269) as instructed,
and it is the second cut inside
publishafter #270. It changes no ABI, no wire,and no phase boundary:
render→publish→capture→announcestill run inthe one synchronous task before paint, which is why the cut had to remove work
rather than move it to
capture. #68's capture deferral is unaffected and stillfollows.
Provenance
agent-authored)