Skip to content

fix(compiler): restore the hook-memo ratio guards and gate Lynx bench fixtures in PR CI - #1583

Merged
trueadm merged 4 commits into
mainfrom
claude/dreamy-bardeen-97aubr
Oct 2, 2026
Merged

trueadm merged 4 commits into
mainfrom
claude/dreamy-bardeen-97aubr

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

node benchmarks/bench.mjs --ratios hook-memo breached 9 guards on main. Neither cause is in the inline memo tier: application-side memo counts were exactly at their designed values. Two unrelated changes produced the breaches, and the weekly Bench job never reached its ratio step to report them.

1. Eight hook-allocation guards: root update cost, not memo cost (harness attribution)

  • Per-site attribution of the observed bundle puts every excess event in the runtime's same-component root.render() path. That is 2 functions per update (renderOwner.request, renderOwner.retry) and 10 arrays per update (the root transaction's OffscreenCapture eight, its undo log, and ROOT_RENDER_TRANSACTIONS). Both compiler variants show the same counts.
  • git bisect over run.mjs output (each commit's own runner, current dependencies) gives first bad commit 5f7a457 (fix: retain suspended roots without a boundary #833, root render transactions). Its parent measures 0/0 on every eligible hit. fix: retain suspended roots without a boundary #833 never touched this benchmark, and packages/octane/audit/root-suspension-performance.md documents this cost as accepted.
  • Fix: a hook-free Driver control runs the identical phase sequence. Every scenario is reported net of the driver's same-phase counts, and the run fails if a scenario falls below the driver. Raw counts stay in the JSON. Two new guards (driver_hit_functions ≤ 2/render, driver_hit_arrays ≤ 10/render) pin the root update cost so it can't grow silently.
  • Sensitivity check: the corrected runner reports identical net counts on both sides of fix: retain suspended roots without a boundary #833. Against 814a3c1 (before closure-free lowering, perf(octane): lower memo hooks to closure-free caches #788) it still breaches the same 7 memo guards the README recorded for that baseline.

2. inline_memo_snapshot_slots (provider-output): a real compiler regression

  • Bisect: first bad commit 5ead1ff (feat: add async signals and streaming SSR #1069, async signals). Any identifier {expr} hole now lowers to the signal-capable bindSignalChild binding. That branch skipped the compilerCacheArray auto-memo region the only-child path wraps around compiler-calculated descriptor arrays. As a result an unchanged list reached childSlot twice per update, for the list and its item.
  • Fix (compiler): wrap the signal-capable binding in the same region. Only an unchanged plain data array can hit. A signal handle or any other value fails compilerCacheArray and rebinds every render, and the identity miss rebuilds a previously cached array. The count returns from 256 to 0.

3. Why CI never saw this

The weekly Bench run failed before --ratios for different reasons over time:

Weeks Failing step Cause
08-31 to 09-14 workerd app workloads run.mjs couldn't import octane, since fixed on main
09-21 Lynx diagnostic fixtures instrument-source.test.mjs: Could not resolve "octane/internal/context" in a copied main-renderer.ts
09-28 Lynx diagnostic fixtures first-screen-template.test.mjs: No matching export ... "universalBlock", fixed on main by #1391 (09-29)

These Lynx stage/list tests compile copies of packages/lynx/src but only ran weekly, so source changes broke them unseen. This PR adds both suites to ci:workflow:test, which the lint job runs on every ready PR, and asserts that the PR list stays aligned with bench.yml. On this branch every pre-ratio step of bench.yml passes locally.

Validation

  • pnpm format:check (scoped pnpm format:files:check on changed files: clean)
  • pnpm typecheck (scoped pnpm typecheck:files: clean)
  • pnpm test (not run in full; see targeted)
  • targeted tests (rebased on main 18fbcb0; the full octane run and the full bench ran on the pre-rebase base 3994e1e):
    • vitest packages/octane/tests/compiler --project octane: 3,571 passed, 1 skipped; auto-memo and auto-calculation suites: 296/296
    • node benchmarks/bench.mjs --ratios hook-memo: 24/24 guards pass (was 9 breaches)
    • vitest --project octane --project octane-prod: 37,009 passed, 5 failed, all in behavior-root.test.ts (a 15 s timeout under CPU load, and 'use dom bindings' getter re-reads). That test's compiled output is byte-identical with main's compiler, and this PR doesn't touch the runtime or that test, so these failures already happen on main in this environment (Node 22.22.0, versus Node 24 in CI)
    • new auto-memo-value-position signal round-trip case: fails in octane-prod when the region's identity miss is removed, and passes on the uncached path
    • pnpm ci:workflow:test: 325/325 on the rebased head, and the new workflow assertion fails without the Lynx gate
    • node --test benchmarks/hook-memo/instrument.test.mjs: 2/2
    • bench.yml pre-ratio steps locally: precise-work 6/6, lynx-table 18/18, lynx-list 5/5, uibench 1/1, workerd verify 17/17 + run, js-framework timing 4/4
    • full node benchmarks/bench.mjs --quick --ratios: stopped after 102/125 suites at the 2 h limit. Over the 101 written results, the committed guards show 23 breaches, none in hook-memo. The deterministic ones (template-call-memo, transition-hooks) are identical when run against main's source. Pre-existing gate failures: tsrx-component-graph (also fails on main), hook-store-composition (fixture compiles identically to main), and ink-cursor-update (timing under load)
    • pnpm sync (no generated changes), pnpm changeset:check, pnpm test:markers:check

Risk / follow-ups

  • Once Bench gets past the Lynx step, its --ratios step will still be red from breaches and gate failures that already exist on main and are independent of this PR (listed under Validation). They need their own fixes.
  • The root update path still allocates 2 closures and 10 arrays per root.render() update. That was fix: retain suspended roots without a boundary #833's documented trade-off. Lazy or reused capture buffers and stable request/retry functions would lower the new driver ceilings. That is a separate runtime optimization that needs timing evidence.
  • The compiler change affects only compiler-calculated renderables that are an element's only child in a component-children body, under autoMemo, which is the scope the region had before feat: add async signals and streaming SSR #1069.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hg86UdUyzRwFTLWhpAMdFE


Generated by Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
The compiler change alters only-child reconciliation when values may be signals or cached arrays; tests cover the main transitions, but the path is update-hot and easy to regress.

Overview
Restores compilerCacheArray around the signal-capable bindSignalChild path when an element’s only child is a compiler-calculated descriptor array under autoMemo. After async signals made every child hole signal-capable, that branch stopped skipping reconciliation for unchanged plain arrays; snapshot-slot churn and extra list walks are fixed while signal handles and identity changes still rebind every render. Hosts that might get dangerouslySetInnerHTML stay on the uncached binding.

The hook-memo harness adds a hook-free Driver control and reports scenario allocation counts net of per-root.render() transaction cost (closures and capture arrays from #833), with new driver_hit_* ratio guards so the root update path cannot grow unnoticed. Docs and ratios.json reflect the attribution.

PR CI now runs the Lynx table/list bench fixture tests via ci:workflow:test, aligned with weekly bench.yml, so Lynx breakages are caught before ratio steps. New auto-memo-value-position tests cover toggling between cached rows and a signal handle and rejecting raw HTML beside unchanged cached rows.

Reviewed by Cursor Bugbot for commit 76843ce. Bugbot is set up for automated code reviews on this repo. Configure here.

claude added 3 commits October 2, 2026 17:42
Since #1069, a renderable `{expr}` hole in a DOM template lowers to the
signal-capable `bindSignalChild` binding whenever the module can carry a
signal handle, which is any identifier hole. That branch returned before the
only-child path that wraps a compiler-owned calculated descriptor array in its
`compilerCacheArray` auto-memo region, so an unchanged array inside a
component-children body reached `childSlot` for the list and each item on
every parent render. The hook-memo provider-output guard
`inline_memo_snapshot_slots` rose from 0 to 256 per 128 updates.

Wrap the signal-capable binding in the same region. Only an unchanged plain
data array can hit; a signal handle or any other value fails
`compilerCacheArray` and rebinds every render, and the existing identity miss
rebuilds a previously cached array after the hole held something else.

The new value-position case switches one calculated child between cached rows
and a signal handle. It fails in the production compile when the region's
identity miss is dropped, and passes on the uncached path too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hg86UdUyzRwFTLWhpAMdFE
Eight hook-memo ratio guards breached on main (eligible hit functions 704,
eligible hit arrays 3,872, and so on) while the inline memo tier's own counts
were unchanged. Per-site attribution put every excess event in the runtime's
same-component `root.render()` path: the per-update request/retry closures
and the root render transaction's undo log, OffscreenCapture arrays and
committed-transaction queue, 2 functions and 10 arrays per render in both
compiler variants. Bisecting `run.mjs` output found 5f7a457 (#833, root
render transactions) to be the first breaching commit; it did not touch this
benchmark, and its documented root-transaction cost is unrelated to hooks.

Add a hook-free Driver control that runs the identical phase sequence, report
every scenario net of the driver's same-phase counts (failing the run if a
scenario falls below it), and keep raw counters in the JSON metadata. Two new
guards pin the driver's per-update cost at its current 2 functions and
10 arrays so the root update path cannot grow silently.

The corrected runner reports identical net counts on both sides of #833, and
against 814a3c1 (before closure-free memo lowering) it still breaches the
same seven memo guards the original measurement recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hg86UdUyzRwFTLWhpAMdFE
The weekly Bench workflow runs the Lynx table-stage and list fixture
contracts before its ratio guards. Those tests compile copies of
packages/lynx/src, and Lynx changes broke them twice (09-21: an unresolved
`octane/internal/context` import; 09-28: a removed `universalBlock` export,
fixed on main by #1391). PR CI never ran them, so each break surfaced only
in the next weekly run and kept every ratio guard from executing.

Add both suites to `ci:workflow:test`, which the lint job runs on every
ready pull request, and assert the two lists stay aligned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hg86UdUyzRwFTLWhpAMdFE
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 17:51
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 2, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Cache skip bypasses innerHTML guard
    • Added !cc.potentialDangerouslySetInnerHTML guard to the signal-child compilerCacheArray condition so innerHTML-eligible hosts always run bindSignalChild, matching the existing guard in the ordinary only-child path.

Create PR

Or push these changes by commenting:

@cursor push 0a56ace6ad
Preview (0a56ace6ad)
diff --git a/packages/octane/src/compiler/compile.js b/packages/octane/src/compiler/compile.js
--- a/packages/octane/src/compiler/compile.js
+++ b/packages/octane/src/compiler/compile.js
@@ -27537,7 +27537,7 @@
 							),
 						),
 					);
-				if (cc.onlyChildText && cc.autoMemoValue === true) {
+				if (cc.onlyChildText && cc.autoMemoValue === true && !cc.potentialDangerouslySetInnerHTML) {
 					// A calculated value can still hold a signal handle, so it keeps the
 					// signal-capable binding. Only an unchanged compiler-owned plain data
 					// array may skip it, exactly as on the ordinary only-child path below;

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit f702046. Configure here.

Comment thread packages/octane/src/compiler/compile.js Resolved
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No size increases and no timing regressions outside noise.

Compares 18fbcb06b with db2d3ddf4 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 3.34 3.90 +16.8% ±27% ⚪ within noise
octane-tsrx replace 7.26 8.66 +19.3% ±36% ⚪ within noise
octane-tsrx add 3.47 3.49 +0.6% ±20% ⚪ within noise
octane-tsrx update 0.41 0.47 +14.6% ±52% ⚪ within noise
octane-tsrx select 0.17 0.19 +11.8% ±90% ⚪ within noise
octane-tsrx swap 0.40 0.44 +10.0% ±49% ⚪ within noise
octane-tsrx remove 0.40 0.43 +7.5% ±53% ⚪ within noise
octane-tsrx runlots 29.91 31.47 +5.2% ±15% ⚪ within noise
octane-tsrx select_lots 0.26 0.25 −3.8% ±42% ⚪ within noise
octane-tsrx clear 44.35 43.31 −2.3% ±6% ⚪ within noise
octane-jsx run 3.79 3.97 +4.7% ±15% ⚪ within noise
octane-jsx replace 8.08 8.32 +3.0% ±27% ⚪ within noise
octane-jsx add 3.32 3.27 −1.5% ±10% ⚪ within noise
octane-jsx update 0.64 0.61 −4.7% ±35% ⚪ within noise
octane-jsx select 0.45 0.45 −0.0% ±27% ⚪ within noise
octane-jsx swap 0.71 0.69 −2.8% ±26% ⚪ within noise
octane-jsx remove 0.72 0.65 −9.7% ±35% ⚪ within noise
octane-jsx runlots 31.52 29.80 −5.5% ±9% ⚪ within noise
octane-jsx select_lots 3.14 2.52 −19.7% ±37% ⚪ within noise
octane-jsx clear 47.57 45.44 −4.5% ±17% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

A host that may receive dangerouslySetInnerHTML, directly or through a
spread, must reach its child binding on every render: that call is where
children and raw HTML are kept mutually exclusive. The ordinary only-child
path already checks this before choosing the cached-array region, but the
region restored around bindSignalChild did not, so an unchanged cached array
let a spread add raw HTML beside still-mounted rows without the error.

Skip the region for such hosts, as the ordinary path does. The new spread
case fails in the production compile without the guard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hg86UdUyzRwFTLWhpAMdFE
@trueadm
trueadm merged commit 97618d7 into main Oct 2, 2026
31 checks passed
@trueadm
trueadm deleted the claude/dreamy-bardeen-97aubr branch October 2, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants