Repository navigation
perf(lynx): mint a first-screen host handle on demand - #270
Merged
Merged
Conversation
A host record has always known its root, id and generation. It spelled all
three through the frozen public handle it minted to hold them, so every reader
that wanted one number allocated the whole seven-field object — and nothing on
the paint path wants the object. The one selector write every painted host
takes builds `r{root}-h{id}-g{generation}` itself, and never read
`handle.selector`: that field is the CSS query form, so the two strings were
never the same string.
The record now names root, id and generation directly, and the direct
first-screen applier builds the same LynxCompactHostRecord the compact-ACK path
already uses, which mints its handle on first read. Adoption, a nodes-ref, an
update or a wire delta each still get one, identical to the eager one and the
same object on every read, because `isPropsOnlyWrite` decides by handle
identity. `assignHostHandle` becomes the sole writer of the handle/generation
pair, so the two can never describe different generations of one host.
A 10,000-row page stops allocating 60,002 frozen handles and 60,002 selector
strings between render and describe; `createHandle` leaves the first-screen
profile entirely.
Refs #247.
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
The first cut of #247's publish work. Per the owner directive
(#247 issuecomment-5485061147): drive the compiled/direct path through
publishuntil the interpreted remainder is gone, using #254's phase segmentation as a
local build tool rather than a merge gate.
#247's own probe table named the target. Inside
publishat 10,000 rows,host record building is 83.2 ms —
cloneProps27.7,createHandle16.9,textValue16.7,planLynxHostPropPatch11.7, selector install 5.8,emitHostNode5.2 — and none of it paints anything. This PR takescreateHandle, and the selector install with it.The handle was never on the paint path
A host record has always known its
root,idandgeneration. It just spelledall three through the frozen public handle it minted to hold them, so every
reader that wanted one number allocated the whole seven-field object. Nothing
before paint wants the object:
r{root}-h{id}-g{generation}itself, and never readhandle.selector— thatfield is the CSS query form,
[octane-ref=…]. The two strings were neverthe same string, which is why nothing noticed.
the event and attachment bookkeeping — wanted one number.
So the record names
root,idandgenerationdirectly, and the directfirst-screen applier builds the same
LynxCompactHostRecordthe compact-ACK pathalready uses, which mints its handle on first read. This is what "extend the
compiled/direct path" means literally here: the compact record is the compiled
path's record shape, and the interpreted first-screen walk was still hand-rolling
an eleven-field literal beside it.
Adoption, a
nodes-ref, an update, or a wire delta each still get a handle,identical to the eager one and the same object on every read.
Changes
@octanejs/lynx:LynxHostRecordnamesroot/id/generation;LynxCompactHostRecord's constructor opens up to carry them;applyLynxFirstScreenDirectbuilds a compact record instead of a literal;installNodesRefSelectortakes the record; 41record.handle.{id,root,generation,type}reads become direct field reads;
assignHostHandlebecomes the single writerof the handle/generation pair.
Measurement, stated honestly
The web lane cannot resolve this cut, and per the directive it does not have
to — "a cut that shows nothing on V8 but is structurally sound still lands; the
target engine has no JIT to hide interpretation behind."
An interleaved 4-round A/B (10,000 rows, 60,002 described hosts, 9 reps/round,
arms alternating) gives base median-of-medians 435.8 ms vs candidate
415.0 ms for
publish— but two of four rounds favour base, within-armspread is ±40 ms, and best-min favours base (332.6 vs 342.2). That is a
non-result, and it is reported as one.
What is exact, and is the reason the cut lands:
createHandleandcreateLynxNodesRefSelectorleave the CPU profileentirely. 60,002 frozen seven-field objects and 60,002 selector strings are
no longer allocated between render and describe.
visitself time falls 132.7 → 97.4 ms per screen.All numbers in this section come from a local
node:inspectorinstrument drivenfrom inside a Vitest run, over a 10,000-row lynx-table-shaped tree on a lean
no-op PAPI, and were taken while this commit sat on the neighbouring stack head.
The commit is byte-identical to the one here; the wall-clock figures are
indicative either way, and the two structural facts above are base-independent.
The ablation that chose this target
Sizing first, from a local instrument over the same 10k tree (median
publish,[min]in brackets; the ablations are correctness-breaking probes, notcandidates):
clonePropscreateHandleplanLynxHostPropPatchMethodology caveat, added after the fact. Each row above is a single run of
each arm, and the follow-up PR produced a case that shows single-run ablation is
not a measurement: a
clonePropssub-change measured −112.3 ms as a single-runablation and −11.5 ms — inside the noise — when the same change was run under
an interleaved A/B. So read this table as an ordering of where the time sits,
which is all it was used for (it is what picked
createHandleand namedclonePropsas the larger next target), and not as effect sizes. Nothing in thisPR's claims rests on these numbers: the reason the cut lands is the two structural
facts above, and the wall-clock A/B in the previous section is reported as a
non-result.
clonePropsis the larger target and is the next PR (#271); it is a differentkind of change (it turns on whether the direct path has a realm boundary to defend
against) and does not belong in this diff.
Two cuts the cheap measurement declined
Recorded because a later reader will otherwise try them:
textValueguard: no effect (417.0 [357.1] vs base 447.1 [358.4] — insidethe noise on median, 1.3 ms on min). Dropped.
selectorgetter on the frozen handle, keeping the handle eager:1.36× worse (606.6 [505.7]). An accessor on a frozen object deoptimizes the
path that reads it. Dropped — which is part of why the whole handle, rather than
one of its fields, is what goes lazy.
Per #264 the cut is structural, 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.
Correctness
The gate the directive keeps in full force is byte-identity between the old and
new publish path. The new regression test paints the same scene through both
arms —
applyLynxFirstScreenDirectand the stagedprepareLynxHostBatch— andasserts, for every host in the captured tree, that the on-demand handle equals
the one the staged path built eagerly, field by field, and that a second read
returns the same object.
Each assertion was falsified before being trusted, per
octane-core-extend:lynxtestsinstalls only requested public-instance selectors for negotiated compact program hosts,keeps a run certifiable for direct teardown after a bound slot is updatedcontainer.root + 1produces the identical adoption snapshot, journal, and physical tree as the staged path,paints a native list into the container the staged path would have producednode.id + 1assignHostHandlewrites the handle but not the generationNo 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.Spec-silent choices, noted rather than asked about
cloneRecordreads the source handle eagerly, forcing a lazy one. That isthe correctness half of the laziness, not a leak:
isPropsOnlyWritedecides byhandle identity, so two copies that each minted their own would report a
write that changed nothing. No paint path reaches
cloneRecord— a clone isalready an update-path allocation.
assignHostHandleis the sole writer of the pair. The record'sgenerationmirrorshandle.generationexactly, so a recreate — which bumpsthe generation and builds the handle for the ACK — must set both or the two
fields would describe different generations of one host. Audited: one write
site for each field, and
typeis never mutated on a record, so the lazilycaptured
typecannot go stale.installNodesRefSelectortakes the record rather than the handle, andspells the attribute out itself rather than deriving it from
handle.selector— which it already did, for the reason above.
Validation
pnpm typecheck— clean, repo-wide--project lynx— 49 files, 767 tests, all passpnpm test— 3 failed, 26,806 passed, 6 skipped across 2,452 files, with6 files red. None is in
lynx, and each is accounted for:suspense-hydration›restores focused input and its selected text after a keyed DOM reorderc124594c7and fails identically (recorded on #269)drei›should match previous onewaitForFunctiontimeout; samenative-demo›escalates cleanup for a detached descendant after its leader exitspackages/aria/tests/hydration.test.tsbeforeAlltimeout, its test skippedhookTimeoutunder a loaded container — passes when run alonepackages/octane/tests/react-hosted/web3-island.test.ts(octane,octane-prod)beforeAlltimeout, its tests skippedc124594c7with this commit absentThe last three are
beforeAllfixture builds hitting the default 10 shookTimeout, which is why 6 files are red but only 3 tests failed: their testsare skipped rather than run. Neither file can reach the lynx host driver.
pnpm format:fileson every changed pathpnpm sync— no generated changesRisk / follow-ups
clonePropsis next, and is now open as perf(lynx): adopt the first screen's props instead of copying them #271, stacked on this branch. It isthe larger half of Attribute the 1.6× web-startup gap to ReactLynx before deciding whether to chase it #247's record-building bucket. The structural argument:
clonePropsexists because host props cross a realm boundary, and the directfirst-screen path has none — the main renderer produced and froze them in this
realm — so the container can adopt an already-immutable bag rather than copy it,
declining to
clonePropsotherwise.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.
perf/lynx-first-screen-lazy-handleholds an earlier push ofthis same commit stacked on feat(lynx): mount a resident program by name, and fold a proved-scalar text hole (#246 E1 + B2) #269's branch, before it was confirmed independent
and re-cut onto
new-lynx. It carries no pull request and can be deleted.Does this change the sequence?
No. This is B under the #247 directive, taken after A (#269) as instructed.
It is independent of A — the commit cherry-picks onto
new-lynxcleanly and isopened against it directly, so #269 and this can gate in either order. It is one
cut inside
publish, and it changes no ABI, no wire, and no phase boundary:render→publish→capture→announcestill run in the one synchronoustask before paint, which is exactly why the cut had to remove work rather than
move it to
capture. #68's capture deferral and theclonePropsadoption areunaffected and still follow.
Provenance
agent-authored)Generated by Claude Code