Skip to content

feat(lynx): stop re-sending an unchanged worklet every render - #124

Merged
Huxpro merged 2 commits into
new-lynxfrom
feat/lynx-universal-prop-equality
Aug 21, 2026
Merged

Huxpro merged 2 commits into
new-lynxfrom
feat/lynx-universal-prop-equality

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Summary

#103 U4c, stacked on #122. U4b made a worklet-bearing keyed list mount in
three commands; the frame after it did not follow. An identical re-render of a
three-row list emitted three update commands, each carrying its row's whole
prop bag, where the same list without the main-thread: prop emitted nothing:

list, identical re-render commands before commands now
plain row × 3 0 0
main-thread:bindtap × 3 update ×3 0

At 1,000 rows that is 1,000 updates per render — the mount cost U4b deleted,
moved to the update path. Measured end to end through createLynxRoot over the
real transport, before and after, and committed as a test.

Why the core was not wrong

bindThreadFunction returns a fresh tagged function every render, and the
core's definition of unchanged is identity, then a bounded structural walk that
stops above a worklet's captures. It says "changed" — correctly, given what it
can see. It has no way to know what the fields of a renderer's descriptor mean,
and teaching it would put main-thread: inside the universal core, which is
exactly what the universal/renderer split exists to prevent.

So it asks instead.

Changes

  • octane UniversalHostUpdateCapability gains an optional
    same(name, previous, next). The core consults it only for a prop it has
    already judged changed
    . That ordering is the whole safety argument: a
    renderer can widen equality and never narrow it, so implementing this can only
    remove update commands — never add, reorder, or force one — and a driver that
    supplies none keeps every existing decision byte-for-byte. The obligation it
    takes on is stated on the interface: "equal" must mean the renderer's own
    applier would have made no change from the update it suppressed.
  • octane universal-core.ts threads the driver's answer through every prop
    diff site — five prop-bag (shallowPropsEqual) and three program-slot — as a
    single resolved-once member, null when the driver claims nothing. The
    consultation is inline at each site rather than behind a helper, so an
    unchanged prop costs exactly what it did before the hook existed.
  • @octanejs/lynx: both drivers answer through a new
    sameLynxUniversalHostPropValue, which claims main-thread: names and
    defers to sameLynxMainThreadPropValue — the same decode-then-compare
    planLynxHostPropPatch already performs. That is what makes suppressing sound
    rather than merely cheaper: an update this removes is one the applier would
    have turned into an empty patch. A malformed descriptor stays the applier's to
    report — a decode that throws declines to call the values equal and ships the
    update that raises it, in the applier's own words at its own point in the
    commit.
  • docs/universal-renderer-architecture.md: the driver interface listing gains
    the new optional member.

Validation

  • pnpm format:check (repo-wide, clean)
  • pnpm typecheck (repo-wide, clean)
  • pnpm test — 5 failed / 21,061 passed / 8 skipped; none of them this diff's
  • targeted: --project lynx 454 passed; --project octane + octane-prod
    12,446 passed in a dedicated run, with zero test failures
  • node benchmarks/bench.mjs --only lynx-table --ratios — PASS, and every
    operation count unchanged (create=1, update10th=100/1000, select=2,
    swap=2, updateStorm=50c/5000). Those fixtures carry no worklet, so the
    driver declines every name — the "additive" claim measured rather than
    argued.

Every failing file in the full run was attributed individually:

Red-first, per changed source file:

reverted what fails
universal-core.ts the core contract test, and both Lynx worklet tests — the core is the funnel
host-props.ts + both drivers both Lynx worklet tests; the core contract test still passes, since it supplies its own driver

Tests:

  • packages/lynx/tests/worklet-template-runs.test.ts — new
    re-sends a row handler only when the handler changes: an unchanged list emits
    nothing, and moving the handler's captures still emits the update on every
    row, because captures are what the handler will act on. The existing
    destroy-with-the-row case gets simpler and stronger at the same time — the
    survivors now keep the executions the run gave them, so it asserts that
    directly instead of chasing whichever execution the frame happened to carry.
  • packages/octane/tests/universal-host-sdk.test.ts — new
    lets a renderer widen prop equality but never narrow it, driving a class
    instance (the core's own documented identity-only boundary) through both a
    prop bag and a program slot in one frame. It pins the ordering directly: the
    renderer is never asked about the unchanged label, which is why a driver
    answering false for a name it does not own cannot turn an equal prop into an
    update. Its sibling keeps the core's own answer when a driver claims no prop names holds the un-hooked path at today's two updates.

Risk / follow-ups

  • A renderer that answers same wrongly suppresses a real update. That is the
    cost of the escape hatch and the reason the obligation is written on the
    interface rather than implied; Lynx discharges it by reusing its applier's own
    predicate rather than writing a second one.
  • The Block core reached this conclusion first, in U4a, with
    sameLynxMainThreadPropValue applied to program-marked slots. Both paths now
    route through that one predicate, so they cannot disagree about what "changed"
    means — which was the point of extracting it.
  • Scope is deliberately the diff, not the encode: the core still re-encodes a
    worklet descriptor every render before discovering it is unchanged. That cost
    is per changed-looking prop rather than per command and is not what the 1,000
    updates measured; shrinking it is a separate question about where encoding
    happens.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

U4b made a worklet-bearing keyed list mount in three commands. The frame after
it did not follow: an identical re-render of a three-row list emitted three
`update` commands, each carrying its row's whole prop bag, where the same list
without the prop emitted nothing. At 1,000 rows that is 1,000 updates per
render — the mount cost U4b deleted, moved to the update path.

The cause is a value the core cannot read. `bindThreadFunction` returns a fresh
tagged function every render, and the core's definition of unchanged is
identity, then a bounded structural walk that stops above a worklet's captures.
It says "changed" and it is not wrong to: it has no way to know what the fields
of a renderer's descriptor mean.

So it now asks. The `updates` capability gains an optional
`same(name, previous, next)`, consulted only for a prop the core has already
judged changed. That ordering is the whole safety argument: a renderer can widen
equality and never narrow it, so implementing this can only remove update
commands, and a driver that supplies none keeps every existing decision
byte-for-byte. The obligation it takes on is that "equal" must mean the
renderer's own applier would have made no change from the update it suppressed.

Lynx answers for `main-thread:` props through `sameLynxMainThreadPropValue` —
the same decode-then-compare `planLynxHostPropPatch` already performs, so a
suppressed update is one the applier would have turned into an empty patch. A
malformed descriptor stays the applier's to report: a decode that throws
declines to call the values equal and ships the update that raises it, in the
applier's own words at its own point in the commit.

The hook is consulted after the core's own answer and inline at each diff site,
so an unchanged prop costs exactly what it did before and a renderer that claims
nothing costs one null check per changed prop. `--only lynx-table --ratios`
holds with every operation count unchanged, which is that claim measured: those
fixtures carry no worklet, so the driver declines every name.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
block-core's write() used the raw structural compare, so a malformed
descriptor already in a slot made every later setKeyedSlotValue throw at
the compare — the slot could never be repaired through the write API.
sameLynxUniversalHostPropValue is the single comparator that owns the
contract (decode failure declines equality and ships the update that
lets the applier report it), so write() now uses it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
@Huxpro
Huxpro changed the base branch from feat/lynx-universal-worklet-runs to new-lynx August 21, 2026 21:03
@Huxpro
Huxpro marked this pull request as ready for review August 21, 2026 21:03
@Huxpro
Huxpro merged commit 2c48a15 into new-lynx Aug 21, 2026
1 of 2 checks passed
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