Repository navigation
perf(compiler): admit destructured props params into autoMemo regions - #640
Merged
Merged
Conversation
Component call sites now receive the compiler-owned whole-region cache when the callee destructures its props param, and call-site eligibility is no longer vetoed body-wide by an unrelated ref or live-import member read — those reads gate per site and per tainted local instead. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Hazard feeds miss pattern sources
- Extended
feedto check the binding pattern (not just the RHS) for deferred-ref reads and imported-member reads, collect free identifiers from pattern expression positions (defaults, computed keys), handle for-of/in with VariableDeclaration left-hand sides, and process nested VariableDeclaration nodes in the walk — all 138 auto-memo and 1068 compiler tests pass.
- Extended
Or push these changes by commenting:
@cursor push cb504a0523
Preview (cb504a0523)
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
@@ -4243,17 +4243,26 @@ function collectAutoMemoLocalHazards(stmts, importedNames) {
const names = new Set();
collectBindings(pattern, names);
if (names.size === 0) return;
- const direct = containsDeferredRefRead(rhs) || containsImportedMemberRead(rhs, importedNames);
- for (const name of names) {
- if (hazards.has(name)) continue;
- if (direct) {
+ const direct =
+ containsDeferredRefRead(rhs) ||
+ containsImportedMemberRead(rhs, importedNames) ||
+ containsDeferredRefRead(pattern) ||
+ containsImportedMemberRead(pattern, importedNames);
+ if (direct) {
+ for (const name of names) {
hazards.add(name);
sourceFrees.delete(name);
- continue;
}
+ return;
+ }
+ const rhsFree = collectFreeIdentifiers(rhs, []);
+ const patFree = collectFreeIdentifiers(pattern, names);
+ for (const name of names) {
+ if (hazards.has(name)) continue;
let set = sourceFrees.get(name);
if (set === undefined) sourceFrees.set(name, (set = new Set()));
- for (const id of collectFreeIdentifiers(rhs, [])) set.add(id);
+ for (const id of rhsFree) set.add(id);
+ for (const id of patFree) set.add(id);
}
};
for (const stmt of stmts) {
@@ -4243,17 +4243,26 @@ function collectAutoMemoLocalHazards(stmts, importedNames) {
const names = new Set();
collectBindings(pattern, names);
if (names.size === 0) return;
- const direct = containsDeferredRefRead(rhs) || containsImportedMemberRead(rhs, importedNames);
- for (const name of names) {
- if (hazards.has(name)) continue;
- if (direct) {
+ const direct =
+ containsDeferredRefRead(rhs) ||
+ containsImportedMemberRead(rhs, importedNames) ||
+ containsDeferredRefRead(pattern) ||
+ containsImportedMemberRead(pattern, importedNames);
+ if (direct) {
+ for (const name of names) {
hazards.add(name);
sourceFrees.delete(name);
- continue;
}
+ return;
+ }
+ const rhsFree = collectFreeIdentifiers(rhs, []);
+ const patFree = collectFreeIdentifiers(pattern, names);
+ for (const name of names) {
+ if (hazards.has(name)) continue;
let set = sourceFrees.get(name);
if (set === undefined) sourceFrees.set(name, (set = new Set()));
- for (const id of collectFreeIdentifiers(rhs, [])) set.add(id);
+ for (const id of rhsFree) set.add(id);
+ for (const id of patFree) set.add(id);
}
};
for (const stmt of stmts) {
@@ -4276,12 +4285,14 @@ function collectAutoMemoLocalHazards(stmts, importedNames) {
seen.add(n);
if (n.type === 'AssignmentExpression' && n.left?.type !== 'MemberExpression') {
feed(n.left, n.right);
- } else if (
- (n.type === 'ForOfStatement' || n.type === 'ForInStatement') &&
- n.left &&
- n.left.type !== 'VariableDeclaration'
- ) {
- feed(n.left, n.right);
+ } else if ((n.type === 'ForOfStatement' || n.type === 'ForInStatement') && n.left) {
+ if (n.left.type === 'VariableDeclaration') {
+ for (const d of n.left.declarations || []) feed(d.id, n.right);
+ } else {
+ feed(n.left, n.right);
+ }
+ } else if (n.type === 'VariableDeclaration') {
+ for (const d of n.declarations || []) feed(d.id, d.init);
}
for (const key in n) {
if (AST_WALK_SKIP_KEYS.has(key)) continue;
@@ -4276,12 +4285,14 @@ function collectAutoMemoLocalHazards(stmts, importedNames) {
seen.add(n);
if (n.type === 'AssignmentExpression' && n.left?.type !== 'MemberExpression') {
feed(n.left, n.right);
- } else if (
- (n.type === 'ForOfStatement' || n.type === 'ForInStatement') &&
- n.left &&
- n.left.type !== 'VariableDeclaration'
- ) {
- feed(n.left, n.right);
+ } else if ((n.type === 'ForOfStatement' || n.type === 'ForInStatement') && n.left) {
+ if (n.left.type === 'VariableDeclaration') {
+ for (const d of n.left.declarations || []) feed(d.id, n.right);
+ } else {
+ feed(n.left, n.right);
+ }
+ } else if (n.type === 'VariableDeclaration') {
+ for (const d of n.declarations || []) feed(d.id, d.init);
}
for (const key in n) {
if (AST_WALK_SKIP_KEYS.has(key)) continue;You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 16cfb6c. Configure here.
domgan-oai
marked this pull request as ready for review
August 8, 2026 01:45
The per-local hazard classification only inspected right-hand sides of top-level declarators and bare loop lefts, so a hazard riding the pattern itself (a `current` or computed binding key, a default reading a ref or live import) or routed through a nested-block or for-of declaration escaped the taint and could witness a region dep. Feed every declaration at every depth, classify the pattern subtree alongside the source, and feed for-of/for-in bound names from the loop source, restoring the old body-wide veto's full coverage per local. Co-Authored-By: Claude Fable 5 <[email protected]>
This was referenced Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
function Child({ rows })is treated as the same one-props snapshot asfunction Child(props), so stable-prop call sites of such components gain the whole-region dependency cache and skip the child's update entirely.ref.current/computed-member/live-import member read elsewhere in the parent. Those reads now gate per call site and per tainted local, so e.g. a portal-mountoverlayRef.currentguard no longer disables memoization for every sibling subtree.Why
App, children like<Topology topo={topo} />behind reference-stable snapshots), a ui-only commit re-entered every subtree: ~148µs per commit vs ~1.7µs for the fixture's Viewport-leaf workaround, 960-commitpan_zoomsamples at 142ms vs 1.6ms.ordinaryPropsParamfailed), and the oneoverlayRef.currentread in the body killedautoMemoCallsitesSafefor all call sites.Defs/ChartsStrip/Sparks/IconLayer— including the 150-iconcreateElementde-opt layer — bail completely on ui commits; the dashboard minus the spread-bearingTopologydrops from ~228µs to ~3–6µs per commit in-page, with the harness's Node-replay byte-parity gates green throughout.Topologyitself still cannot bail because its rows carry{...e.attrs}spread bags, which the callee proof correctly fails closed on today (follow-up below).Changes
isAutoMemoPropsParam(compile.js): admits anObjectPatternprops param when destructuring it evaluates nothing — fails closed on defaults, computed keys, anycurrentbinding at any depth, array patterns (iterator protocol), and non-identifier rest targets.collectAutoMemoLocalHazards(compile.js): per-local taint replacing the body-widereadsDeferredRef/readsImportedMemberveto. A local is tainted when a ref or live-import member read reaches its value through its initializer, any assignment right-hand side, or a for-of/for-in feed — transitively, including inside nested function values (useCallback(() => ref.current, [])). A site whose free identifiers touch a tainted local falls back; plain-value conditionally-reassigned locals stay clean witnesses (locals re-initialize every body entry).scanComponentBodyno longer collects the now-unused body-wide ref flag.AutoMemoAppruntime fixture gains a destructured-param twin ofRowswith mirrored context-refresh/child-state assertions, running in both the dev andoctane-prodvitest projects.octane, patch).Validation
pnpm format:checkpnpm typecheckpnpm test— 1567 files / 16,965 tests green on this branch (also green twice on the feat(benchmarks): add the svg-dashboard SVG stress suite #635 base during development)auto-memo.test.ts,auto-memo-value-position.test.ts,automemo-render-calls.test.ts(184 tests),packages/octane/tests/compiler(1,061 tests); new tests confirmed red pre-fixpnpm sync— no generated changespan_zoom0.31x react (guard ≤0.7),drag_nodes1.64x (≤2.2),style_spread_pulse1.99x (≤3.0); octane absolute numbers flat-to-better vs same-server pre-change baseline; full harness correctness gates (byte-parity Node replay, namespace census, survivor identity) green with regions skipping.Risk / follow-ups
nonlocalCallSitesexpectations unchanged), and dev/HMR/profile/server builds still emit no regions.{...attrs}) remain excluded from the proof — the measured remaining gap (svg-dashboardTopology, ~130µs of the inline-shape commit); tracked as a separate investigation.listSafe/itemMemo) accept locals as deps without hazard filtering — pre-existing behavior, deliberately not tightened here.Provenance
agent-authored)🤖 Generated with Claude Code
Note
Medium Risk
Changes compiler correctness boundaries for production-only memo regions (refs, live imports, destructuring); semantics are fail-closed and heavily tested, but misclassification could skip caches or risk stale subtrees.
Overview
Widens autoMemo (prod compiler-inferred region caching) so more real-world components and call sites actually get memo regions instead of falling back globally.
Destructured props callees:
isAutoMemoPropsParamtreats a plainObjectPatternparam like(props)— one snapshot at entry — while still rejecting defaults, computed keys, anycurrentbinding, array patterns, and multi-param signatures. Callees such asfunction Child({ rows })can now beautoMemoSafeand emit dependency-cached regions when props stay reference-stable.Per-site hazard gating: The body-wide
readsDeferredRefveto is removed fromscanComponentBody/autoMemoCallsitesSafe.collectAutoMemoLocalHazardstaints component locals that absorb ref reads or live-import member reads (including via destructuring defaults, loops, assignments, and transitive locals). Only call sites whose free identifiers touch a tainted local lose the region; unrelated siblings (e.g. a portalref.currentguard elsewhere) keep caching. Plain locals with only value reassignment stay eligible.Component analysis stores
autoMemoLocalHazardsoncomponentInfoand threads it through compile viactx.currentAutoMemoLocalHazardsfor per-sitedepsSafechecks. Tests cover admission/rejection matrices, hazard scoping, and a runtime twin for destructuredRows.Reviewed by Cursor Bugbot for commit 7ba5e6d. Bugbot is set up for automated code reviews on this repo. Configure here.