Skip to content

perf(universal): retain transported keyed subtrees - #37

Closed
Huxpro wants to merge 1 commit into
perf/lynx-upstream-pacingfrom
perf/lynx-upstream-adoption
Closed

Huxpro wants to merge 1 commit into
perf/lynx-upstream-pacingfrom
perf/lynx-upstream-adoption

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Let plain urgent transported universal roots reuse committed component subtrees when the component, props, consumed contexts, visibility, and dirty epoch are unchanged.
  • Keep transport acknowledgement and listener semantics intact while reducing keyed table render breadth from O(table size) to O(changed rows).
  • Add deterministic Row-render gates and a keyed swap workload to the Lynx table benchmark.

Why

Upstream octanejs#587 already provides the retained-subtree machinery used by local universal drivers. The transported path was still categorically excluded by one this.transport === null predicate even though its full-root versioning, command folding, and accepted listener table are compatible with retained ranges. This layer removes only that exclusion; it does not add another memoization system or loosen the existing Object.is-based component-prop contract.

This is the rebased, independently mergeable replacement for the behavior in #11, frozen at adfad409867733a524c5ab200c15b0510535586d. It does not duplicate upstream octanejs#660/octanejs#661/octanejs#662, and the old PR remains historical provenance.

Changes

  • packages/octane/src/universal-core.ts: allow retained adoption for plain urgent transported full-root attempts; replay, transition, bridge, and full-root-scheduled attempts remain excluded, and scoped owned updates remain local-only.
  • packages/octane/tests/universal-transport.test.ts: cover stable host identity, child-local state, mount/cleanup effects, live transported listeners, consumed-context invalidation, prop changes, and keyed reorders over the real MessageChannel loopback.
  • benchmarks/lynx-table: count Row body executions only in profile builds, add a far keyed swap, record render breadth beside commands/bytes, and fail on breadth drift at 1k and 10k.
  • benchmarks/baselines/ratios.json: add eight adoption guards. Pure reorder requires exactly zero Row renders; the known 997-command LIS reorder is represented as a 1.0× upper-waterline instead of a permissive 500× ratio.
  • Add a patch changeset for octane.

Stack

The fork review stack is GitHub Stack octanejs#36, managed with the official gh stack extension. Upstream delivery remains bottom-to-top because fork-only branches cannot be simultaneous PR bases in octanejs/octane.

Simplification

  • Kept the product change to the existing eligibility predicate; no compiler assist, alternate reconciler, or app workaround was added.
  • Removed exact component-body logs from ordinary correctness tests. Observable identity/state/effect/context/listener contracts stay in Vitest; exact render counts live in the deterministic benchmark boundary where a reverted predicate provably fails.
  • Replaced the swap guard's two-command model plus maxRatio: 500 with the measured 997-command waterline plus maxRatio: 1, and made the zero-render swap gate strictly zero.
  • Replaced dated/source-issue baseline notes and the stale “transport must re-execute” runtime comment with durable behavior descriptions.
  • Listed only the object driver's container-independent capabilities in the transport test adapter, removing an incompatible generic spread and making the changed runtime/test files typecheck cleanly.

Performance audit

Exact comparison:

  • parent: 1d61be7be2286a8de430a780f83975182de89d32
  • candidate: 71e1b8a88a8c3e37cc005d37a8e6f75cf31088b4
  • host: 32× Intel Xeon Platinum 8336C, Linux 5.15.120.bsk.3-amd64, Node 22.22.2, Chromium 149.0.7827.55
  • raw results (ignored local artifacts): p2-parent-gate-disabled-wire.json, p2-final-candidate-wire.json, p2-final-profile-cold.json, p1-candidate-web.json, and p2-final-candidate-web.json under benchmarks/lynx-table/attribution/results/

Deterministic render breadth and wire

The parent breadth capture uses the final benchmark harness with the sole P1 transport exclusion restored; exact P1/P2 product builds are used for the cold and Web measurements below. Two drift-checked iterations per scale:

LYNX_TABLE_SCALES=1000,10000 BENCH_JSON=... node benchmarks/lynx-table/run.mjs 2
node benchmarks/bench.mjs --ratios lynx-table
operation P1 Row renders P2 Row renders commands P1 → P2
update10th @1k / @10k 1,000 / 10,000 100 / 1,000 100 / 1,000 → unchanged
select @1k / @10k 1,000 / 10,000 2 / 2 2 / 2 → unchanged
swap @1k / @10k 1,000 / 10,000 0 / 0 997 / 997 → unchanged

Select stays exactly 237 serialized bytes at both scales. Unpaced storms stay at 50 commits and 5,000/50,000 commands; the paced 1k update storm stays at 50 total commits, 3 frame-consuming commits, 300 commands, and 3 pumped frames. All 23 applicable ratio guards pass.

Red-check: restoring the parent exclusion at 1k makes update10th/select/swap render 1,000 rows and breaches the new guards by 10×, 500×, and the strict-zero threshold respectively. Restoring the final code returns 100/2/0 and a clean ratio run.

Fresh-realm operation latency

Exact-SHA profile bundles, five fresh realms per target; values are first-operation median ms [min–max]. Every semantic oracle and keyed-survivor check passed.

operation @1k P1 P2 delta
swap 128.1 [122.5–135.5] 92.9 [82.9–100.5] -27.5%
select 53.9 [52.0–66.5] 32.8 [30.3–33.4] -39.1%
update10th 63.5 [61.8–70.9] 35.8 [33.8–41.0] -43.6%
create (negative control) 343.1 [338.3–380.6] 334.3 [322.7–354.3] -2.6%
replace (negative control) 405.6 [399.4–426.9] 414.7 [402.2–443.2] +2.2%
clear (negative control) 83.5 [82.4–86.5] 84.6 [83.2–91.9] +1.3%

No adverse cell reaches the 5% expanded-repeat threshold.

Lynx-for-Web latency

Same production build, driver, host window, and fresh-page protocol; medians of n=5 [min–max], zero DNF:

operation P1 @1k P2 @1k delta P1 @10k P2 @10k delta
create 338.5 [332.8–366.0] 329.6 [325.0–333.9] -2.6% 2799.0 [2789.0–2923.1] 2882.7 [2813.0–2957.8] +3.0%
update10th 59.9 [58.1–63.0] 31.8 [31.1–32.9] -46.9% 542.5 [503.1–550.1] 295.9 [280.7–369.8] -45.5%
select 48.2 [46.1–60.6] 28.0 [27.5–28.3] -41.9% 397.8 [389.6–430.3] 153.1 [130.9–182.8] -61.5%
update storm 214.4 [201.7–259.3] 98.4 [97.1–99.2] -54.1% 1888.8 [1852.6–1957.8] 863.6 [814.7–903.6] -54.3%
select storm 143.7 [138.8–177.2] 27.6 [24.4–29.3] -80.8% 554.1 [487.1–588.7] 235.5 [221.1–244.0] -57.5%

The 10k create median is +3.0%, below the repeat threshold and contradicted by the exact-SHA fresh-realm create control (-2.6%); it is classified as host noise, not a product regression.

Production Web bundle is 385,596 → 385,573 bytes and gzip 103,536 → 103,532 bytes. SHA-256: parent 3e25e1da19a8369524bb793db9bafbfea11d463c915b6a708c8e49086fd7ff69, candidate 65e026f73dd62bb6484c2806979eec1a2d4f0a1c9938ef6108893bd6f765865a. Profile hashes are parent fedeb5a65ec1ba9213f722fc997ddc975579609baed94f53bac717261bee662d, candidate 07c72dbaeae4bfcade074fbebeb33d2570a858eb91bed0f009fe0e2f0f5d579a.

Validation

  • focused universal transport: 2 projects, 48/48 tests
  • related Octane universal + all Lynx suites: 45 files, 686/686 tests
  • performance red-check with the P1 exclusion restored; final node benchmarks/bench.mjs --ratios lynx-table: 23/23 applicable guards passed
  • scoped typecheck:files for runtime/test; benchmark app tsrx-tsc --noEmit; production Vite/Rspeedy builds compile workload.ts (it is not owned by a standalone TypeScript project)
  • pnpm format:files:check for all 8 changed files
  • pnpm sync; git diff --check; final worktree clean

Risk / follow-ups

  • Adoption requires a component boundary and identity-stable component props. Inline-host item lambdas still execute, although P0's wire diff continues to suppress unchanged host commands.
  • Replay, transition, bridge, and full-root-scheduled attempts deliberately remain ineligible; widening any of those paths needs its own bookkeeping proof.
  • The far transposition still emits 997 move commands. That is a pre-existing LIS behavior (final order and survivor identity are guaranteed, a minimal move set is not); this PR adds a strict waterline but does not optimize it.
  • The small negative-control spreads are host-bound. Deterministic render and wire counts are the acceptance signal.

Provenance

Port and simplify #11 at frozen source adfad40. Keep correctness tests at observable transport boundaries and move exact render breadth into the deterministic Lynx table ratio harness.
@Huxpro

Huxpro commented Aug 11, 2026

Copy link
Copy Markdown
Owner Author

Conclusion: close as landed upstream. The retained-subtree adoption path is represented by octanejs/octane PR 696 and should not be merged again from this stack.

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