Skip to content

perf(lynx): plan a host create without diffing it against nothing - #272

Merged
Huxpro merged 1 commit into
new-lynxfrom
perf/lynx-create-prop-patch
Sep 2, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
perf/lynx-create-prop-patch

Conversation

@Huxpro

@Huxpro Huxpro commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

The third cut of #247's publish work. Per the owner directive
(#247 issuecomment-5485061147): drive the compiled/direct path through publish
until the interpreted remainder is gone, using #254's phase segmentation as a
local build tool rather than a merge gate.

After #270 and #271, a fresh profile of publish on their head names
planLynxHostPropPatch at 120.6 ms over 7 screens, 17.2 ms per screen — the
largest contained frame left inside publish that is neither the walk itself nor
the capture that follows it. This PR stops it from diffing against nothing.

Every host patch a first screen plans is a create

Not "almost every". A census on the 10,000-row tree, counting calls and how many
arrive with an empty previous:

calls 40002  creates 40002  createFastPath 30002  createTextOnly 0  createAttributeProps 10000

40,002 of 40,002. There is no update in a first screen — that is what a first
screen is — and yet the planner derived the previous side of a diff for every
one of them: Object.keys on the same empty bag 40,002 times, each allocating an
empty array, plus a localPlainPropBag on it; and for the 10,000 that reach the
body past the shared-patch fast path, an id, class, inline style, dataset, CSS
scope and main-thread ref derived from that bag as well. All of it lands on the
same constants every time.

One body, two entry points

planLynxHostCreatePatch is deliberately not a second planner. This module
already carries a warning against exactly that shape — classifyLynxHostUpdate's
comment says its verdict "is exactly planLynxHostPropPatch(...).requiresRecreate"
so the two cannot drift — and a hand-written create planner would be the drift
that comment is about.

So the seven previous-side derivations are named (PreviousPropSide), the
diff body is unchanged and shared, and a create enters it with that side already
known as a frozen constant. There is nothing to keep in step: the comparisons, the
refusals, and the patch construction are one implementation, entered two ways.

The update path is byte-identical, deliberately. Each derivation stays exactly
where it was, guarded by side === null, because several of them can throw and
hoisting them would reorder which refusal a malformed bag reports first. The
create side can be hoisted precisely because none of the seven can throw on an
empty bag.

Changes

  • @octanejs/lynx: PreviousPropSide and NO_PREVIOUS_PROPS in host-props.ts;
    planLynxHostPropPatch and the new planLynxHostCreatePatch become two entry
    points onto one planHostPropPatch body; the ten create call sites in
    host-driver.ts — first screen, template run, program plan, compact ACK,
    main-thread prop install, node materialization — take the create entry point.
    The two genuine update sites keep planLynxHostPropPatch.

Correctness

The gate the directive keeps in full force is byte-identity between the old and
new publish path. Here that is a differential over the two entry points: for
19 scenes, each landing on a different branch of the shared body,
planLynxHostCreatePatch(type, next) must equal
planLynxHostPropPatch(type, empty, next) — for both spellings of "no previous
props" the driver used to pass, a prototype-less bag and a plain {}. Eight
refusal scenes assert the two produce the same message, not merely that both
throw.

Two assertions exist because deep equality would not see them:

  • the shared patch objects are compared by identity, since a propless host
    and a single-class host are meant to share one frozen patch across the whole
    first screen;
  • an attribute a create never had writes nothing, which the differential
    cannot see because a break there moves both arms together.

Each was falsified before being trusted, per octane-core-extend:

break red lynx tests
the create's previous names constant is not empty 51
the create's previous class constant is not '' 14
the create's previous id constant is not null 12
the create's previous CSS scope constant is not null 12
the create's previous dataset constant is not EMPTY_DATASET 12
a create's absent attribute answers '' rather than null 2
both arms' absent attribute answers '' 1
a create skips the shared-patch fast path 1

The last two are the reason those two extra assertions are in the diff: without
them, the first stays green across all 800 lynx tests and the second stays
green across all but the differential.

Measurement

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 within each round):

round base publish candidate publish
0 316.6 330.4
1 348.3 315.3
2 312.4 310.0
3 305.3 314.9

Median-of-medians 314.5 → 315.1; best-min 254.0 → 254.2; two rounds each way,
arms fully overlapping. That is a non-result and it is reported as one.

What is exact, and is the reason the cut lands, is what stops happening per
first screen at 10,000 rows:

  • 40,002 Object.keys calls on an empty bag, and the 40,002 empty arrays they
    allocate
    ;
  • 40,002 localPlainPropBag calls on that same bag;
  • for the 10,000 creates that reach the body: decodeMainThreadRef, classProp,
    normalizeLynxClass, normalizeLynxInlineStyle,
    normalizeLynxDatasetFromNames and decodeLynxCSSScopeMetadata on it, plus a
    hasOwn per attribute prop.

Roughly 160,000 calls and 40,002 allocations, removed rather than relocated. That
distinction is what separates this cut from the one #271 declined: there the
deleted scan's per-node comparisons moved into the loop that absorbed it, so only
loop overhead was actually removed. Here nothing moves — the work has no
destination, because its answer was already a constant.

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.

Spec-silent choices, noted rather than asked about

  1. The update path keeps every derivation in place. Hoisting them behind one
    previousPropSide(previous) call would be tidier and would reorder refusals
    for a malformed previous bag — decodeMainThreadRef would throw before the
    reserved-namespaced-prop check. A stored bag was validated when it was
    created, so this is unreachable today; it is still not worth spending.
  2. All ten create sites move, not only the first screen's. The two that passed
    a literal {} rather than the driver's shared empty bag move too: both are
    empty, both are plain, and planLynxHostCreatePatch answers each identically —
    which the differential asserts for both spellings rather than assuming.
  3. NO_PREVIOUS_PROPS.dataset is EMPTY_DATASET, the same shared object
    normalizeLynxDatasetFromNames returns for a bag with no data- props, so
    sameDataset's identity short-circuit still fires for a propless create.
  4. side is PreviousPropSide | null rather than a boolean, so the constants
    live next to the interface that names them and a reader can see what a create's
    previous side is without reconstructing it from the guards.

Validation

  • pnpm typecheck — clean, repo-wide
  • --project lynx — 49 files, 800 tests, all pass
  • pnpm test — running against this head; result posted below when it lands
  • pnpm format:files on every changed path
  • pnpm sync — no generated changes

No 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. The counts above come from a local census instrument that
is not part of this diff.

Risk / follow-ups

  • planLynxHostCreatePatch is a new export from core/host-props.ts, which is
    internal to the package. Nothing in src/index.ts re-exports it.
  • This PR is stacked on perf(lynx): adopt the first screen's props instead of copying them #271, which is stacked on perf(lynx): mint a first-screen host handle on demand #270. GitHub retargets it as
    those merge.
  • What is left inside publish, and why it is not here. The per-host
    state.generations.set(id, 1) — 60,002 map writes of one repeated value —
    already has implicitInitialGenerations for exactly this on the compact path,
    but turning it on for the direct first screen would disable a later
    incrementalCompact mount on the same container. That is a behaviour trade, not
    a free cut, and the lane cannot price it (ablation 321.9 against a 315.7 base).
    It belongs to the device round, which is where the directive puts the
    performance verdict.
  • Branch naming. The harness assigned claude/octane-issue-66-phase-a-7wz97z;
    this repo's create-a-pr requires a type-prefixed topic branch so the label bot
    can read the type from it. The topic branch is used, and the deviation is
    flagged here rather than resolved unilaterally.

Does this change the sequence?

No. This is B under the #247 directive, taken after A (#269) as instructed,
and it is the third cut inside publish after #270 and #271. It changes no ABI,
no wire, and no phase boundary: render → publish → capture → announce
still run in the one synchronous task before paint, which is why the cut had to
remove work rather than move it to capture. It changes no refusal ordering
either — the update path's derivations stay exactly where they were, and a
create's cannot throw. #68's capture deferral is unaffected and still follows.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Every host prop patch a first screen plans is a create — 40,002 of 40,002
on the 10,000-row tree — and the planner derived the previous side of a
diff for every one of them: `Object.keys` on the same empty bag 40,002
times, and for the 10,000 that reach the body past the shared-patch fast
path, an id, class, inline style, dataset, CSS scope and main-thread ref
derived from it too. All of it lands on the same constants every time.

Name those constants and let a create enter the diff body with them
already known. This is deliberately not a second planner: the comparison
body, the refusals and the patch construction stay one implementation
entered two ways, so the create and the update cannot answer differently.
The update path keeps every derivation exactly where it was, because
several can throw and hoisting them would reorder which refusal a
malformed bag reports first; a create's cannot throw on an empty bag,
which is what makes hoisting its side sound.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy

Huxpro commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

pnpm test against this head

4 failed, 26,838 passed, 6 skipped across 2,452 files, with 7 files red.

The test total moves 26,819 → 26,848 against #271's head: +29, exactly the new
tests in this diff
(19 differential scenes, 8 refusal scenes, the shared-object
identity test, and the absent-attribute test).

None of the seven is in lynx, and none can reach the Lynx host driver — the diff
touches packages/lynx/src/core/host-props.ts and host-driver.ts only, which no
red file imports:

red shape why it is not this diff's
suspense-hydration › restores focused input and its selected text after a keyed DOM reorder failed test browser focus/selection; red on c124594c7 with this whole stack absent (recorded on #269)
drei › should match previous one failed test headless screenshot comparison, 30 s waitForFunction timeout; same
native-demo › escalates cleanup for a detached descendant after its leader exits failed test process-tree signal escalation on a 100 ms budget, on a test named for macOS; same
monaco-editor-browser › mounts a real editor with workers and accepts typed input failed test — locator.click 30 s timeout re-run alone on this head: still red; re-run alone on the base commit 03e68116d with this diff absent: red identically. Not load-induced and not this diff's — a headless click into a worker-backed Monaco editor in this container
packages/aria/tests/hydration.test.ts beforeAll timeout, its test skipped the fixture build exceeds the default 10 s hookTimeout under load (verified passing alone on the base, 19.17 s wall, on #271)
packages/octane/tests/react-hosted/web3-island.test.ts (octane, octane-prod) beforeAll timeout, its tests skipped the RainbowKit fixture exceeds the same 10 s budget in this container; red on c124594c7 with this stack absent

The three beforeAll timeouts are why 7 files are red but only 4 tests failed:
their tests are skipped rather than run.

One change against #271's run, reported rather than smoothed over:
syntax-highlighter › fails closed for missing, extra, renamed, collided, stale, and removed-lane evidence was red there and is green here, while
monaco-editor-browser went the other way. Both are container-resource tests at
the edge of a fixed deadline, and the monaco one was checked against the base
commit rather than assumed.

Validation otherwise: pnpm typecheck clean repo-wide, --project lynx
49 files / 800 tests all passing, pnpm sync no generated changes,
pnpm format:files on every changed path.


Generated by Claude Code

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.

1 participant