Skip to content

[lynx-perf 3] Compiler-backed auto-memo for keyed list items — kill O(N) replay breadth #4

Closed

Description

@Huxpro

Depends on: #1 landed (bail decisions need sameUniversalHostPropValue; identity-compared fresh props lists never bail). This is the dominant remaining point-update gap: post-#1, select@10k is 857ms vs vue-vdom 164 / react 170 — nearly all of it background replay breadth.

The measured problem

The owner for selected state is the list-owning component, so universalFor re-runs its item lambda for ALL 10k rows on every select — 10k fresh universalProps arrays, 10k universalValue wrappers, 10k record diffs — for a change affecting 2 rows. Compiled shape:

universalFor(rows, (row,i) => row.id, (row,i) =>
  universalValue(plan1, [ universalComponent('lynx', Row, universalProps([
    ["set","row",row], ["set","isSelected", selected===row.id],
    ["set","onSelect", select], ["set","onRemove", remove] ])) ]))

Ceiling anchor: the ReactLynx bench app with hand-written memo(Row) does select@10k in ~170ms. React makes users write memo; octane's compiler sees every @for item and its full props list — automating the bail is the thing octane is better positioned to do than React. (README already claims memo bailouts — first find why the universal path doesn't get them before writing new machinery.)

Change

  1. At the universalComponent reconcile boundary in universal-core.ts: identical component reference + props list equal by value (per-entry ["set", key, value], values via sameUniversalHostPropValue) ⇒ skip re-rendering that child owner entirely — retain records, emit nothing.
  2. Context correctness: a bailed subtree still re-renders when a context it consumes changes (bail means "props didn't change", never "nothing changed"). Explicit test: context update through a memo-bailed @for item.
  3. Compiler assist (compile-universal.js): mark @for item lambdas whose output depends only on (item, index, provably-stable captures) as memo-eligible — the hook-deps closure analysis already computes this; unstable captures opt out (correct-by-default). No new user-facing API; an opt-OUT directive is acceptable.

Constraints

  • React-memo semantics: bail ⇒ no render, no effects re-run, refs stable.
  • Keyed reorder (LIS path) still works on bailed items: moves without re-renders (cover swapRows).
  • Suspense/error/Activity boundaries inside items keep their retained-episode bookkeeping.

Acceptance (rig)

  • Deterministic: item-renders counter on select@1k drops 1000 → 2; update10th@10k renders exactly the changed rows.
  • select@10k lands in the 150–250ms band (references: vue-vdom 164 / react 170 same host); update10th@10k in the 200–350ms band.
  • All universal suites green (event-scope, portals, composition); create/FCP untouched.

Activity

  1. Huxpro commented on Aug 9, 2026

    @Huxpro
    OwnerAuthor

    Implemented in #11 (stacked on #10 → #1). Measured outcome, and one finding that changed the shape of the fix:

    The README's memo-bailout claim was one predicate away from true on Lynx. Following this issue's directive ("first find why the universal path doesn't get them"), the answer turned out to be: octanejs#587 already landed generic retained-subtree adoption at the universalComponent reconcile boundary — identical component + shallow-equal props + stable consumed contexts + no pending updates ⇒ adopt the committed subtree, render nothing, emit nothing — but retainEligible excluded transported roots wholesale. The transport commit machinery was already adoption-safe (whole-tree version acknowledgement, in-place listener-table edits that only retire re-staged hosts, monotonic universal IDs), so the fix is removing that one exclusion, plus regression tests. No new reconcile machinery and no compiler assist needed — the adoption boundary fires for any @for item that renders a component child, which is the compiled shape quoted above.

    Deterministic acceptance (rig, drift-checked, wire counters byte-identical before/after):

    op item renders before → after floor
    select@1k 1000 → 2 2 ✅
    select@10k 10000 → 2 2 ✅
    update10th@10k 10000 → 1000 exactly the changed rows ✅
    swap@1k/@10k (new op) 1000/10000 → 0 keyed reorder of adopted items, no renders ✅

    Context correctness is pinned by a new test: a theme change through retained-prop @for items re-renders all of them, and they re-adopt once the provider settles. Effects don't re-run, listeners announced at mount keep dispatching across retained commits, LIS reorder moves adopted subtrees with zero renders. 8 new ratio guards; red-check breaches them at 10×/500×.

    Wall clock (same host, back-to-back, medians n=3), @10k:

    op before after band target vue-vdom / react (same run)
    select 813 (5.32×) 274 (1.95×) 150–250 141 / 174
    update10th 888 (4.57×) 473 (2.60×) 200–350 182 / 265
    updateStorm 3590 (1.09×) 1460 (0.51×) — 2885 / 6121
    selectStorm 1039 (0.71×) 487 (0.35×) — 1383 / 2671

    select@1k reaches vue-vdom parity (28ms vs 24, 1.15×), and both 10k storms now beat vue-vdom outright and land at vue-vapor's level. The 150–250 / 200–350 bands are not fully reached (274 / 473): what remains is the O(N) item-lambda re-run itself — 10k fresh universalProps arrays + descriptor allocations + shallow-compares per parent render — which adoption by design does not remove. That's the honest residual for the remaining ~130/~200ms, a candidate follow-up alongside #5/#7.

    One deliberate deviation from the sketch above: the bail predicate stays Object.is shallow-equality (exact React memo semantics) rather than per-entry sameUniversalHostPropValue — the compiled @for shape passes identity-stable rows and useCallback-stable handlers, so identity comparison already meets every acceptance floor. The value-semantic predicate stays available as a follow-up if real apps pass fresh-but-equal props objects.

    Also newly measured while adding the swap op: a rows-1↔998 transposition costs 997 move commands against the 2-move model (LIS moves the spanned window; final order and survivor identity are the contract, move-set minimality is not). Pinned as a KNOWN GAP waterline guard so it can't silently grow.


    Generated by Claude Code

  2. Huxpro commented on Aug 11, 2026

    @Huxpro
    OwnerAuthor

    Live-main audit (2026-08-11): landed upstream as octanejs#696. Upstream explicitly carried the Huxpro #11 retained transported-subtree mechanism: select executes two Row bodies and update10th executes only changed rows. Closing the fork issue as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions