Repository navigation
perf(lynx): fold a compile-time-known text child onto its text host - #250
Conversation
A `<text>` whose lone child is authored text compiled to two elements: the host and a carrier holding nothing but the string. Where the renderer accepts that string as a `text` prop, the carrier is a second element created, addressed, retained and torn down to say what its parent could have said. The universal compiler now writes the string as a prop and emits no carrier, gated on a renderer capability plus the host's accepted-prop list — the capability is the claim that prop and child render identically, the prop list names which hosts hold it. The fold is narrow by construction: a lone child that is authored text, no sibling, and no existing writer of `text` through a binding or an unordered prop bag. Folding at plan level alone would make the main-thread backend refuse the program, so `text` becomes a fourth dense scalar on a `text` host across all three readers of that route: the runtime applier, the runtime route computation, and the build-time emitter. A node routed by one and not the others is a first screen whose two arms paint different trees. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
`first-screen-template.test.mjs` compiles a row through the real TSRX pipeline, so it is the end-to-end evidence for the fold and it went red on its own: 7001 elements at 1000 rows became 6001. The premise counts move with it, and the node list is now asserted directly rather than only its length — the two holes keep the carrier that addresses their slot and the one literal does not, which is the whole claim in one line. The two `papi-run` records are the oracle #242 Cause A names, kept beside the checked-in baselines under their own label: 70,000 creates at 10k rows against 60,000, zero spread over five repetitions, same worktree and same harness bytes with only `packages/` swapped between the arms. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
|
| failing test | project | what it is |
|---|---|---|
packages/drei/tests/browser/upstream-e2e.browser.test.ts — "should match previous one" |
drei-adapted-browser |
Playwright WebGL screenshot e2e, page.waitForFunction 30 s timeout |
packages/rspeedy-plugin-octane/tests/native-demo.test.ts — "escalates cleanup for a detached descendant after its leader exits" |
rspeedy-plugin |
process-tree kill escalation, a macOS Lynx Explorer path, running on Linux |
packages/octane/tests/browser/suspense-hydration/suspense-hydration.test.ts — expect(after.scrollTop).toBe(7) |
octane browser | Playwright scroll-restoration assertion |
Proven pre-existing rather than assumed. Reverted packages/ to origin/new-lynx
in this same worktree — so the harness, the browser, and the machine state are
byte-identical between the arms — and ran exactly those three files:
Test Files 3 failed (3)
Tests 3 failed | 38 passed (41)
Same three, same assertions, on base source with none of this change present.
The unhandled error in the run (Cannot read properties of null (reading '_location') from jsdom's runAnimationFrameCallbacks, originating in
packages/redux-toolkit/tests/conformance/query.test.ts) is a teardown race in
jsdom, not an assertion, and equally untouched by a Lynx-gated compiler fold.
For the record, the projects that own this change were green on their own:
--project lynx 48 files / 728 passed, --project octane 472 files / 8377
passed | 1 skipped.
Generated by Claude Code
…atic-text-onto-text-host
Base merge onto the landed E2 stack — re-validated, both suites greenThe conflict-discipline promise in the body ("this one merges onto whatever of The merge was textually clean, which is not the same as safe here. This PR
The counts go up, not sideways: +6 lynx and +2 octane are the tests the
CI has not run against this head, and that is not about this diffRun 33313346813 was The wider state, since it affects how this PR should be gated: Root cause not established — recorded as hypothesis, not verdict, per the Generated by Claude Code |
Two divergences the fold left between the arms that mount one program: - The staged mount-template-run path planned a scalar-route creation patch from id and classes alone, so a text host whose content the compiler folded (or whose text prop is bound) painted empty whenever the run was ineligible for the dense fast path. planScalarClassAndIdCreation now writes the content under the dense applier's exact guard. - The ordinary command patch coerced any non-null text value to an attribute write, while the dense applier and the compiled program write only non-empty strings. The prop takes the carrier's semantics now: a non-string paints empty, create-time empty content makes no call, and emptying existing content writes '' over the carrier's own channel rather than an attribute removal the PAPI does not promise. Both red-verified against the merged tree: the staged run painted no text at all, and text: 0 painted "0" on the command path only. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
A record that does not name its code cannot be compared to another one, and this probe's largest managed-heap row is one `WeakRef` per painted element — so its readings move whenever the compiler changes how many elements a row paints. That is not hypothetical. The record checked in with this probe was taken before #250 folded a compile-time-known text child onto its `text` host. Taken again after, on the same probe at the same scale, the retained total is half what it was and the `WeakRef` row falls from 70,000 nodes to 60,000 — exactly one fewer per row. A reader holding both files could not have told which was which, because neither said. The generated report now names the commit and whether the tree was dirty, in its own second paragraph rather than only in the JSON, because the report is the artifact that gets quoted. Stamping is never fatal: a checkout without git records a null stamp rather than losing the measurement. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
…t build (#246 E1, part 3) Completes E1 with B2 and the build-time drift gate the addressing needs. B2 rides #250's fold rather than adding wire vocabulary, per the §6.4 ruling that a scalar text slot is a binding `{ valueIndex, name: 'text' }` on a `text` host and therefore absent ABI work rather than deferred work. `{expr as string}` as the lone child of a text-absorbing host now folds onto that host as a `['text', slot]` binding, the carrier is never painted, and the slot keeps the existing `p:text` kind. The proof is read off the authored JSX, not the plan node: `compile.js` strips every TS-only wrapper before printing, so by codegen the cast is gone. The compiled child is checked too, so a hole that folded to static text or to a nested plan is not this. A lying cast cannot paint a wrong tree — `text` on a `text` host takes the carrier's semantics in all three appliers, each rendering a non-string as empty rather than coercing it. The drift gate lands in the Rspack loader, which is where one build sees both compiles of a module. Each compile reports the addresses it emitted with the digest of the wire surface it derived them from; a disagreement per `(module, index)` fails the build naming the module, rather than shipping a positional address that would mount a plausible wrong tree. The module id is package-relative, computed from the path alone, and deliberately not the compiler's canonical module id: that one is project-relative and falls back to the absolute path outside the project root, which would put a build machine's filesystem layout into a shipped chunk and disagree between a monorepo build and a consumer's build of the same source. A module with no package-relative name declines addressing in both compiles alike and keeps descriptor mounts. `programAddressing` is on by default for an rspeedy application build that configures a backend, and refused for an isolated thread graph. Both layers inherit the backend when it is on, because the background decides eligibility by running the same derivation as a pure oracle. The backend signature is bumped and its digest repinned, since the derivation's design-spec header changed: its stated blocker — that a plan the compiler produced cannot say a hole is text — is what B2 removes. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Summary
#242 Cause A, per the split in
#242 issuecomment-5467072534.
A
<text>whose lone child is authored text used to compile to two elements:the
texthost, and a carrier element holding nothing but the string. Where therenderer accepts that same string as a
textprop, the carrier is a secondelement created, addressed, appended, retained and torn down to say what its
parent could have said itself.
The compiler now writes the string as a prop and emits no carrier. The bench
row goes from 7 elements to 6.
Why
The renderer really does accept it, and this is not an approximation of the
carrier — it is the same code path. In
@lynx-js/[email protected],dist/elements/XText/XText.jscomposesRawTextAttributesintoXText(the<text>element, registered asx-text) — the same handler class<raw-text>itself uses, which doesregisterAttributeHandler('text', true)and lists
textinobservedAttributes. Settingtexton the host andappending a carrier that holds it reach the identical attribute handler.
Verified on web. Not verified on native Lynx — see Risk.
Changes
The fold —
packages/octane/src/compiler/compile-universal.jshostAbsorbsTextChild(type, state)gates on two independent things, and both areload-bearing: a renderer capability
text-child-prop, which is the semanticclaim that the prop and the child render identically, and
textappearing inthat host's
validation.hostPropslist, which says which hosts hold the prop.Neither alone is sufficient.
compileHostElementAstfolds only when all of these hold — each conditionearns its place:
thing the parent renders;
kind: 'text', which is authored JSX text and string literals and never adynamic hole — a hole's value is unknown here and its slot must still be
addressed;
propsSlot, which builds an unordered bag at runtime the compiler cannotprove lacks the key — refuse rather than race it;
textprop and notextbinding.The scope this actually needed — see the note below. Folding at plan level
alone makes the main-thread backend refuse the program, so
textbecomes afourth dense scalar, on a
texthost only, across all three readers of thatroute:
packages/lynx/src/core/host-driver.ts—applyDenseScalarHostPropsreadsprops.text, lets atextbinding overwrite it, and writessetAttribute(node, 'text', …)betweensetIdandsetClasses;packages/lynx/src/core/host-driver.ts— thedynamicRoutescomputation, nowasking the new
isDenseScalarHostProp(type, name)rather than an inlined list,so the two runtime readers cannot drift apart;
packages/lynx/src/compiler/emit-main-thread-program.ts—scalarHostProps(type)returns the text-extended set for
type === 'text'only, used bydynamicRouteand by the route-0 refusal's offending-prop finder;emitScalarPropsemits the write in the applier's order, with the applier'sstring-only guard.
A
viewcarryingtextstays off the route in every one of them: nothing elsein the intrinsic set renders a
textprop, so that is a program the command pathwould paint differently.
Renderer declaration —
packages/lynx/src/config.tsandpackages/lynx/src/config.runtime.js, changed identically becausepackages/lynx/tests/config.test.tscompares them value-for-value: bothrenderers gain the
text-child-propcapability, andhostProps.textgains'text'.Backend cache signature —
packages/lynx/src/compiler/index.tsbumps tolynx-main-thread-program/9andmain-thread-backend-signature.test.tsrepinsthe digest, which is what that test's own comment prescribes.
Validation
pnpm format:check— viapnpm format:fileson all changed files, cleanpnpm typecheck— viapnpm typecheck:files; see the multiset notepnpm test— see the note at the end of this sectionOracles from the Cause A ruling, measured with
node stages/papi-run.mjs --cells octane --scales 10000 --reps 5, both arms inthis container, same worktree and same harness bytes — only
packages/wasswapped between runs, so no benchmark difference can enter the comparison:
__CreateRawText__CreateText__CreateViewpapiCreateCalls)__AppendElement__SetAttribute__SetClasses/__AddEvent/__FlushElementTreepapiCreateCalls≤ 60,000 — met, exactly at the bound. 7.0 → 6.0 elementsper row. Every count has zero spread across all five repetitions: these are
exact, not medians of noise. The trade is legible — one fewer element created
and one fewer append, against one added
setAttribute.The pre-populated first screen collects it twice, because it also pays an
identity read per element: creates 70,042 → 60,029,
__GetElementUniqueID70,042 → 60,029,
__AppendElement70,041 → 60,028,__SetAttribute40,028 →50,041 — 310,195 → 290,169 total calls, −6.5%.
The other two oracles. That
__GetElementUniqueIDrow is the adoptionoracle, answered by the runtime rather than by a test: adoption reads one id per
described element, and the count tracks the new element bill exactly, so adoption
ran and adopted the whole tree. The committed-tree controls are the arm-vs-arm
tests in
lynx-main-thread-program-first-screen.test.ts— "takes the samefirst-screen IDs as the interpreted encoding" and "paints the tree the
interpreted encoding paints, with the same event tokens" — green, alongside the
~15
adopts …tests beside them.Both records are checked in under their own label:
benchmarks/lynx-table/stages/results/cause-a-{base,cand}-*.New test, red-verified —
packages/octane/tests/lynx-target-templates.test.ts,"folds a compile-time-known text child onto its host, and only that". Renders
through
MainRenderer.renderLynxFirstScreenand assertshostCountis 2 for<view class="a"><text class="c">{'x'}</text></view>and 3 for{props.label as string}. The second arm is the boundary, not an oversight: ahole's value is unknown at build time, so its carrier stays, and folding that
needs the scalar text slot kind of Cause B (#246).
A second test went red on its own, which is the best kind —
benchmarks/lynx-table/stages/first-screen-template.test.mjscompiles a rowthrough the real TSRX pipeline, so it is the end-to-end evidence:
hostCount7001 → 6001 at 1000 rows, id stride 9 → 8. It now asserts the node list
directly rather than only its length:
The row's two holes keep their carriers and its one literal does not, which is
the whole of Cause A in one line — and the reason
valuesstays at 3 whilenodesdrops: nothing about what the row binds moved, only what it paints.Wire-level pins updated, not repinned blindly —
packages/octane/tests/lynx-block-template-lowering.test.tsnow shows the rowwire's trailing
{ type: '#text', parent: 5, props: { value: 'x' } }gone andnode 5 become
{ type: 'text', parent: 0, props: { class: 'col-remove', text: 'x' } }.Slot order (
0:class, 2:value, 4:value) is unchanged and the event nodes remapconsistently (
{node:4},{node:7}→{node:3},{node:5}), which is the check thatsays nothing the benchmark addresses moved.
npx vitest run --project lynx— 48 files, 728 passednpx vitest run --project octane— 472 files, 8377 passed | 1 skippedfirst-screen-template2/2,evidence3/3,plus
analyze,operations,papi-analyze,papi-report,papi-instrument,instrument-source,production-ab,profile-realms,mts-profile,dom-attach-analyze,dom-attach-report— 107 further tests,0 failures.
pnpm typecheck:fileson the changed TS reports 5 errors, all 5pre-existing: stashed the diff, re-ran, diffed the sorted error multisets,
empty. No new errors.
pnpm sync— clean, no generated changes.pnpm test(repo-wide) — in flight at the time of opening.compile-universal.jsis the shared universal compiler, so the two owningprojects are not the whole surface even though the fold is capability-gated to
Lynx. Result posted as a comment on this PR rather than edited into this
body.
Risk / follow-ups
carrying forward. The overnight plan scoped Cause A as a short lowering PR.
It cannot be:
compile-universal.jscallsemitLynxMainThreadProgramwith notry/catch, so a folded node the backend does not route fails the buildwith
LynxMainThreadEmitRefusal: node N (text) carries "text", which only the command path writes. Octane paints 7 elements per benchmark row where Vue paints 4 — audit the row's element diet; it is also the ART-ceiling denominator #242's own body said this had to be a "compiler +first-screen + background change in lockstep, not a renderer patch"; that
turned out to be exactly right. Reported to Octane paints 7 elements per benchmark row where Vue paints 4 — audit the row's element diet; it is also the ART-ceiling denominator #242.
another is a first screen whose two arms paint different trees. The route
computation now shares
isDenseScalarHostPropwith the applier; the emitternecessarily re-derives it at build time and carries a comment saying so. That
duplication is inherent to a build-time backend and is the one place a future
scalar could silently diverge.
RawTextAttributesevidence above isfrom
@lynx-js/web-elements. Whether native Lynx'stextelement honours atextattribute identically to araw-textchild is not established here.The device-boundary oracle was retired in the Cause A ruling, so nothing in
this PR claims it.
hostProps.textnow accepts an authoredtextprop. Widening theaccepted-prop surface is deliberate and named in the Cause A ruling, but it
does mean
<text text="hi" />is now valid authoring on this renderer.step to
papiCreateCalls≤ 50k is the scalar text slot kind, which is a wireABI change and belongs with E1 (E1 design: how a background-originated mount names an MTS-resident program (#230) #246).
for how Cause B is priced. E2 → E3 → E1 stands and nothing here reorders it.
Cause A is independent and done. Cause B stays with E1's wire-ABI design
(E1 design: how a background-originated mount names an MTS-resident program (#230) #246) — a scalar text slot kind is a change to what the wire can name,
which is the question E1 answers. What moves is its price: Cause A needed
three readers to agree about a prop the wire vocabulary already had; Cause B
adds a new slot kind, so it needs those three plus the derivation, the delta
protocol, and the background encoder to agree about a shape none of them can
express today. The remaining
papiCreateCallsbill is 60,000 → 50,000 and itis entirely Cause B's — nothing else in the row is foldable.
new-lynx, and it toucheshost-driver.ts— which perf(lynx): stop describing unbinds a teardown's own destroy subsumes #245/perf(lynx): drop the teardown record mirror #248/perf(lynx): stop describing detaches a clear's own destroy performs #249 also touch. Per the standing rule thelater change yields: this one merges onto whatever of that stack lands first.
No force-pushes on any open PR.
claude/octane-issue-66-phase-a-7wz97z, butcreate-a-prmandates aperf/topic branch so
label-pr.ymlcan derive the type label. Topic branch used;flagging rather than silently picking a side.
Provenance
agent-authored)Generated by Claude Code