Skip to content

perf(lynx): fold a compile-time-known text child onto its text host - #250

Merged
Huxpro merged 4 commits into
new-lynxfrom
perf/lynx-fold-static-text-onto-text-host
Aug 31, 2026
Merged

Huxpro merged 4 commits into
new-lynxfrom
perf/lynx-fold-static-text-onto-text-host

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 30, 2026

Copy link
Copy Markdown
Owner

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 text host, and a carrier element holding nothing but the string. Where the
renderer accepts that same string as a text prop, the carrier is a second
element 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.js composes RawTextAttributes into XText (the
<text> element, registered as x-text) — the same handler class
<raw-text> itself uses, which does registerAttributeHandler('text', true)
and lists text in observedAttributes. Setting text on the host and
appending 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.js

hostAbsorbsTextChild(type, state) gates on two independent things, and both are
load-bearing: a renderer capability text-child-prop, which is the semantic
claim that the prop and the child render identically, and text appearing in
that host's validation.hostProps list, which says which hosts hold the prop.
Neither alone is sufficient.

compileHostElementAst folds only when all of these hold — each condition
earns its place:

  • exactly one child, because a carrier standing beside a sibling is not the only
    thing the parent renders;
  • kind: 'text', which is authored JSX text and string literals and never a
    dynamic hole — a hole's value is unknown here and its slot must still be
    addressed;
  • no propsSlot, which builds an unordered bag at runtime the compiler cannot
    prove lacks the key — refuse rather than race it;
  • no existing static text prop and no text binding.

The scope this actually needed — see the note below. Folding at plan level
alone makes the main-thread backend refuse the program, so text becomes a
fourth dense scalar, on a text host only, across all three readers of that
route:

  • packages/lynx/src/core/host-driver.ts — applyDenseScalarHostProps reads
    props.text, lets a text binding overwrite it, and writes
    setAttribute(node, 'text', …) between setId and setClasses;
  • packages/lynx/src/core/host-driver.ts — the dynamicRoutes computation, now
    asking 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 by
    dynamicRoute and by the route-0 refusal's offending-prop finder;
    emitScalarProps emits the write in the applier's order, with the applier's
    string-only guard.

A view carrying text stays off the route in every one of them: nothing else
in the intrinsic set renders a text prop, so that is a program the command path
would paint differently.

Renderer declaration — packages/lynx/src/config.ts and
packages/lynx/src/config.runtime.js, changed identically because
packages/lynx/tests/config.test.ts compares them value-for-value: both
renderers gain the text-child-prop capability, and hostProps.text gains
'text'.

Backend cache signature — packages/lynx/src/compiler/index.ts bumps to
lynx-main-thread-program/9 and main-thread-backend-signature.test.ts repins
the digest, which is what that test's own comment prescribes.

Validation

  • pnpm format:check — via pnpm format:files on all changed files, clean
  • pnpm typecheck — via pnpm typecheck:files; see the multiset note
  • pnpm test — see the note at the end of this section
  • targeted tests

Oracles from the Cause A ruling, measured with
node stages/papi-run.mjs --cells octane --scales 10000 --reps 5, both arms in
this container, same worktree and same harness bytes — only packages/ was
swapped between runs, so no benchmark difference can enter the comparison:

host call, create@10k base candidate delta
__CreateRawText 30,000 20,000 −10,000
__CreateText 30,000 30,000 0
__CreateView 10,000 10,000 0
creates (papiCreateCalls) 70,000 60,000 −14.3%
__AppendElement 70,000 60,000 −10,000
__SetAttribute 0 10,000 +10,000
__SetClasses / __AddEvent / __FlushElementTree 40,000 / 20,000 / 1 40,000 / 20,000 / 1 0
total host calls 200,001 190,001 −5.0%

papiCreateCalls ≤ 60,000 — met, exactly at the bound. 7.0 → 6.0 elements
per 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, __GetElementUniqueID
70,042 → 60,029, __AppendElement 70,041 → 60,028, __SetAttribute 40,028 →
50,041 — 310,195 → 290,169 total calls, −6.5%.

The other two oracles. That __GetElementUniqueID row is the adoption
oracle, 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 same
first-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.renderLynxFirstScreen and asserts hostCount is 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: a
hole'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.mjs compiles a row
through the real TSRX pipeline, so it is the end-to-end evidence: hostCount
7001 → 6001 at 1000 rows, id stride 9 → 8. It now asserts the node list
directly rather than only its length:

view<--1, text<-0, #text<-1, text<-0, #text<-3, text<-0   (props: { text: 'x' })

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 values stays at 3 while
nodes drops: 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.ts now shows the row
wire's trailing { type: '#text', parent: 5, props: { value: 'x' } } gone and
node 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 remap
consistently ({node:4},{node:7} → {node:3},{node:5}), which is the check that
says nothing the benchmark addresses moved.

  • npx vitest run --project lynx — 48 files, 728 passed
  • npx vitest run --project octane — 472 files, 8377 passed | 1 skipped
  • Bench stage tests, all green: first-screen-template 2/2, evidence 3/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:files on the changed TS reports 5 errors, all 5
    pre-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.js is the shared universal compiler, so the two owning
    projects 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

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Huxpro and others added 2 commits August 30, 2026 09:49
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

Huxpro commented Aug 30, 2026

Copy link
Copy Markdown
Owner Author

pnpm test (repo-wide): 3 failed | 26,770 passed | 1 skipped — all 3 pre-existing

Completing the one unchecked box in the body.

Test Files  3 failed | 2448 passed (2451)
     Tests  3 failed | 26770 passed | 1 skipped (26774)
    Errors  1 error
  Duration  2488.98s

The three failures, and why none is this diff's:

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

Huxpro commented Aug 30, 2026

Copy link
Copy Markdown
Owner Author

Base merge onto the landed E2 stack — re-validated, both suites green

The conflict-discipline promise in the body ("this one merges onto whatever of
that stack lands first") is discharged. new-lynx now carries #235/#237/#238/
#239/#240/#243/#245/#248/#249, so this branch merged origin/new-lynx
(432c6485) rather than the other way round. Merge commit 3e827c8c, no
force-push.

The merge was textually clean, which is not the same as safe here. This PR
changes packages/lynx/src/core/host-driver.ts, and the stack that just landed
changed that same file by +109/−80 — #245's teardown route, #248's mirror
deletion, #249's detach elision, plus the gate fix on top. A clean three-way
merge says the edits did not overlap by line; it says nothing about whether
applyDenseScalarHostProps and the new dynamicRoutes computation still agree
with the reworked teardown path. So both owning suites were re-run on the merged
head rather than trusted from before:

suite pre-merge (body) post-merge
npx vitest run --project lynx 48 files, 728 passed 48 files, 734 passed
npx vitest run --project octane 472 files, 8377 passed | 1 skipped 472 files, 8379 passed | 1 skipped
bench stage suite (node --test stages/*.test.mjs) 117 184 (18 files)

The counts go up, not sideways: +6 lynx and +2 octane are the tests the
merged stack brought with it — including the destroy-then-re-create regression
added by the gate fix on #249 — and they pass with this fold applied. The bench
stage suite grows because #251-adjacent stage tests landed with the stack.

pnpm sync after the merge: clean, no generated changes.

CI has not run against this head, and that is not about this diff

Run 33313346813 was
created for 3e827c8c and is queued. That is expected for a draft — the guard in
ci.yml skips every expensive job — but the two required-check reporters are
queued too, which is why GitHub reads mergeable_state: unstable.

The wider state, since it affects how this PR should be gated: ci.yml's first
job, classify changeset release, is sitting queued without ever starting on
both the new-lynx push run
(33312574787, since
12:50 UTC) and #251's ready-for-review run
(33312665521). Those
are two different concurrency groups, so they are not queued behind each other.
label-pr.yml uses the same blacksmith-4vcpu-ubuntu-2404 label and has
completed six recent runs in 8–11 s, so the runner label itself resolves.

Root cause not established — recorded as hypothesis, not verdict, per the
#230 protocol. What is verified is the consequence: the last ci.yml run to
reach success was run 434 on 2026-08-27, so the merged E2 stack currently
on new-lynx has had no CI executed against it.


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
@Huxpro
Huxpro marked this pull request as ready for review August 31, 2026 02:39
@Huxpro
Huxpro merged commit 4081baf into new-lynx Aug 31, 2026
15 of 19 checks passed
Huxpro added a commit that referenced this pull request Aug 31, 2026
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
Huxpro added a commit that referenced this pull request Sep 1, 2026
…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
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