Skip to content

perf(lynx): classify host updates without building the prop patch (issue-66 A4) - #92

Merged
Huxpro merged 1 commit into
new-lynxfrom
perf/lynx-host-prop-classify
Aug 19, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
perf/lynx-host-prop-classify

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Summary

updates.classify is the renderer's question "can this host be updated in place,
or must it be recreated?". Both Lynx drivers answered it by running the full
semantic prop diff and keeping one boolean:

return planLynxHostPropPatch(type, previous, next).requiresRecreate ? 'recreate' : 'update';

The patch was then discarded. On the background client driver nothing else ever
looked at it, and the main thread rebuilt the same patch from the same props bag
a moment later in prepareLynxHostBatch. This is the run-and-discard double diff
called out in issue #66 §3 A4.

classifyLynxHostPropUpdate answers the same question directly. Losing a CSS
scope is the only condition that makes a host un-updatable in place, and that
verdict needs neither the attribute diff, the dataset bag, the class
composition, nor the patch object.

Why

The classifier runs once per updated host per commit on both threads. On the
lynx-table 10k operation sequence that is 51,065 calls, each of which built and
froze a patch object, an attribute-patch array, and a dataset bag that nothing
read.

This also gives the delta work a prop-bag-independent classification contract to
build on: the later A4/A5 slices change how an update is represented on the wire,
and updates.classify must not be reaching into a full props bag to answer a
question about CSS scope.

Changes

  • packages/lynx/src/core/host-props.ts: add classifyLynxHostPropUpdate plus
    the shared assertNoDirectMainThreadTextProps helper that both it and
    planLynxHostPropPatch now use for the raw-text rejection.
  • packages/lynx/src/core/client-driver.ts, host-driver.ts: both
    updates.classify implementations call it.
  • packages/lynx/tests/host-prop-classification.test.ts: the differential.

What is skipped is construction and comparison, never a rejection and never a
property read. Every validation planLynxHostPropPatch performs still runs in
the same order, so a rejected update is still rejected on the same thread with
the same error rather than relocating to a main-thread host fault; and every
walk is kept so both paths touch the same own-properties of the bag in the same
order, with only the allocation dropped. That second half matters because the
work that looked skippable is throw-free but not read-free: normalizeLynxClass
cannot reject a value, attributeValue coerces only <image> sources, and the
dataset normalizer rejects exactly one name (data-) — but all three read from
the bag on their way there. Keeping the reads costs nothing measurable (see
below) and removes an entire class of divergence rather than arguing it is
unreachable.

Validation

Differential: for every type × fragment pair over 7 host types and 32 prop
fragments — 7,168 pairs, plus 21,504 merged-bag pairs — the classifier and
planLynxHostPropPatch().requiresRecreate must agree on the verdict and on
the exact thrown message. The corpus is itself guarded (>20 recreate verdicts,
>200 rejections) so the agreement cannot go vacuous.

Red-green verified — each deliberate break was applied, the suite run, and the
break reverted:

break result
drop dataset name validation 3 failed / 1 passed
drop image attribute coercion 3 failed / 1 passed
drop inline style validation 3 failed / 1 passed
drop main-thread ref decode 2 failed / 2 passed
drop reserved-namespace rejection 2 failed / 2 passed
invert the recreate verdict 3 failed / 1 passed
(restored) 4 passed
  • pnpm typecheck
  • pnpm sync (no generated changes)
  • pnpm format:files on every changed path
  • targeted: pnpm vitest run --project lynx — 29 files / 366 tests passed
  • pnpm test — 20,961 passed, 5 failed
  • pnpm format:check (not run repo-wide; format:files covers every path this
    diff touches)

All 5 failures are pre-existing in this container, established rather than
assumed: the same five files were re-run on the base commit c3baf805a and
produced the identical five failures, same test names.

file why
drei/tests/browser/upstream-e2e.browser.test.ts fetches raw.githack.com → raw.githubusercontent.com; the Three.js loader rejects with Could not load …. No commit in this stack touches packages/drei.
rspeedy-plugin-octane/tests/native-demo.test.ts the "escalates cleanup for a detached descendant" case issue #66 §2 already names as pre-existing here
rspeedy-plugin-octane/tests/browser/web-host.test.ts browser
octane/tests/browser/suspense-hydration/… browser, DOM renderer only
dropzone/tests/probes/hydration.test.ts browser, DOM renderer only

The container ships Chromium 1194 while playwright 1.61 wants 1228; the
symlink workaround issue #66 §2 prescribes is what lets these projects run at
all, and is the likely reason the browser cases are unstable here.

Measurement

Same-window A/B, quiet host (1-minute load 0.27 on 4 logical CPUs), AB/BA
alternation. Absolute milliseconds are host-bound and are not comparable across
sessions or hosts.

Seam — both classifiers over the 4,000 real (type, previous, next) triples
captured from the lynx-table 10k sequence (the distribution is 99.9% #text
{value}→{value}, the rest view {class}→{class}), 40 passes, n=9:

median per call
planLynxHostPropPatch().requiresRecreate 28.5 ms (27.4–29.6) 178 ns
classifyLynxHostPropUpdate 6.4 ms (6.0–6.9) 40 ns

same-window ratio 0.224×; the ranges do not overlap. An earlier variant that
dropped the property reads as well as the allocations measured 0.221×/39 ns — the
same to within noise, which is why read parity was kept.

End-to-end — full runTable(10000) through the real dual-thread path, fresh
process per sample, n=7: base 7,367.2 ms (6,967.5–7,822.4), candidate 7,263.3 ms
(6,754.5–7,395.9), ratio 0.986×. A second window measured 0.979×.

That end-to-end number is not a performance claim. The ranges overlap
heavily, and the arithmetic says they should: 51,065 calls × ~138 ns saved is
about 7 ms against a ~7,300 ms sequence, or 0.1%. The honest reading is that
this removes provably redundant work and per-update allocation from the commit
path with no measurable whole-path effect in this harness.

The per-stage intervals this harness reports are not offered as supporting
evidence, in either direction. updates.classify runs during commit planning,
before dispatch, so it is inside none of them; and dispatchMs is not a wire
cost — the in-process ContextProxy delivers synchronously, so the interval
around context.dispatchEvent (transport.ts:336-338) contains the whole
main-thread receive pipeline plus the harness's own per-message JSON.stringify
byte counter (workload.ts:94). Reading it as serialization cost would be a
mistake; benchmarks/lynx-table/README.md already says wall clock belongs to
the browser harness and this runner owns deterministic counts.

Not measured: the browser stage harness (stages/run.mjs) and FCP. Neither
should move — this touches no first-screen path.

Risk / follow-ups

  • The behavioural contract is now pinned by the differential rather than by
    sharing one function body. If a future change teaches planLynxHostPropPatch
    a second recreate trigger, host-prop-classification.test.ts fails until
    classifyLynxHostPropUpdate learns it too — that is the intended tripwire, and
    the corpus guards keep it honest.
  • planLynxHostPropPatch itself is unchanged and still owns every path that
    actually consumes a patch.
  • The classifier is deliberately not faster than it needs to be. The remaining
    cost is the walks that can reject, and shrinking those further would mean
    moving a rejection off the background thread — a behavioural change, not an
    optimisation, and not one this slice should make.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

`updates.classify` answers one question — can this host be updated in place,
or must it be recreated. Both Lynx drivers answered it by running the full
semantic prop diff and keeping a single boolean, then discarding the patch.
On the background client driver nothing else ever read it, and the main
thread rebuilt the same patch from the same props bag a moment later in
`prepareLynxHostBatch`. That is the run-and-discard double diff named in
issue #66 §3 A4.

`classifyLynxHostPropUpdate` answers it directly. Losing a CSS scope is the
only condition that makes a host un-updatable in place, and that verdict
needs neither the attribute diff, the dataset bag, the class composition, nor
the patch object.

What is skipped is construction and comparison, never a rejection and never a
property read: every validation still runs in the same order, so a rejected
update is still rejected on the same thread with the same error instead of
relocating to a main-thread host fault, and every walk is kept so both paths
touch the same own-properties of the bag in the same order.

Differential: 7,168 type x fragment pairs plus 21,504 merged-bag pairs must
agree with `planLynxHostPropPatch().requiresRecreate` on the verdict and on
the exact thrown message, with corpus guards so the agreement cannot go
vacuous. Red-green verified across six deliberate breaks.

Measured same-window on a quiet host, AB/BA. Seam, over the 4,000 real
triples captured from lynx-table@10k, 40 passes, n=9: 178 ns/call ->
40 ns/call, ratio 0.224x, ranges separated. End-to-end runTable(10000),
fresh process per sample, n=7: 7,367.2 ms -> 7,263.3 ms, ratio 0.986x with
overlapping ranges — within noise, and the arithmetic agrees (51,065 calls
times ~138 ns is ~7 ms of ~7,300 ms). No whole-path performance is claimed.

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.

1 participant