Repository navigation
perf(compiler): admit host-element spread bags into autoMemo regions - #642
Merged
Merged
Conversation
A spread bag on a HOST element is one setSpread binding whose bag is
reachable only from deps the region guard already witnesses, so skipping on
unchanged dependencies is the no-op a re-entry would have been. Callee
bodies like svg-dashboard Topology's {...e.attrs} rows now earn the
call-site region and keyed-list caches; component-tag spreads keep failing
closed, and the spread argument still walks under every other rule.
Co-Authored-By: Claude Fable 5 <[email protected]>
trueadm
marked this pull request as ready for review
August 8, 2026 11:16
95 tasks done
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
containsAutoMemoUnsafeStructure) now admits spread bags on host elements, so bodies like svg-dashboard Topology's<path d={e.d} {...e.attrs}>no longer disqualify the component's call-site region cache or its keyed-list caches. Component-tag spreads keep failing closed, and the spread argument still walks under every other rule (accessors, computed members, ref reads).Why
setSpreadbinding whose bag is reachable only from dependencies the region guard already witnesses (every free identifier of a region is classified by the existing proofs; unwitnessed names fail closed independently of spreads). A skip on unchanged deps is therefore the no-op a re-entry would have been — the same pure-render immutable-snapshot argument that already admits member-read bindings likeclass={e.cls}. The statically invisible bag keys hold up case by case:refin a bag:setSpreaddiffs refs by identity (unchanged value is a no-op even on re-entry), queues detach on removal/swap with commit ordering, and compiled teardown detaches spread-supplied refs on unmount. A skipped region keeps the same ref attached to the same element — identical to aReact.memobail. (The explicitref={…}attribute rejection stays as the pinned static-escape philosophy.)callSiteOkexcludes them, andisAutoMemoPropsParam's rest admission documents that a getter-bearing props object must never reach a cached region.Changes
packages/octane/src/compiler/compile.js: the walk marks spread attributes of!isComponentTagelements into a per-invocation WeakSet during the element's visit (parents walk before their attributes), and the blanketSpreadAttribute/JSXSpreadAttributerejection exempts marked nodes.hostMountSafestays spread-free throughisHostMountSafeTree's own attribute check; dev/server output is unchanged since every consumer gates onctx.autoMemo.packages/octane/tests/auto-memo.test.ts: compiler admissions (props-object callee, destructured@forTopology shape, tsx map-lowered rows) and pinned rejections (component-tag spread in a body and at a call site, inline getter bag, computed-member argument, explicit ref beside a bag); plus a runtime cached-region scenario — bag applies on mount, a skip keeps the bag's ref and handler live (and pins mutation-invisibility under unchanged deps), re-entry applies changed keys, clears vanished keys, and swaps the bag ref old → null → new, unmount detaches.benchmarks/baselines/ratios.json: svg-dashboard guard notes updated with the 2026-08-08 observations (no ceiling changes).octane, patch).Validation
pnpm format:check(scopedformat:files:checkover the changed files)pnpm typecheckpnpm test— full suite green on this branch's basepackages/octane/tests/auto-memo.test.ts(142 tests, octane + octane-prod projects); spread/ref/keyed neighbor suites. Red-checked both directions: without the widening the new tests fail (no region); with a deliberately neutered dep comparison the DOM re-diff assertions catch the wrong skip.pan_zoom134.0 ms → 0.6 ms,tooltip_swarm51.5 → 0.8 ms; committed-shape A/B isolating this change:charts_tick4.2 → 2.9 ms,tick_sparse3.7 → 0.8 ms,series_toggle3.0 → 2.1 ms, always-miss ops flat within noise (drag_nodes+~0.1 ms, ~1.4%). Full 4-flavorbench.mjs svg-dashboard --ratiosrun passes all guards (re-run on this rebased base with the React-Compiler react column).Risk / follow-ups
React.memo) already makes; the runtime test pins it deliberately.Provenance
agent-authored)Note
Medium Risk
Widens compiler memoization eligibility; correctness hinges on region guards and spread re-diff parity, though the new compiler and runtime tests target the risky cases.
Overview
autoMemo no longer treats
{...bag}on host elements as an automatic disqualifier. Patterns like<path d={e.d} {...e.attrs}>can keep region and keyed-list caches; component-tag spreads still fail closed, and unsafe spread arguments (getters, computed keys, refs) still do.In
containsAutoMemoUnsafeStructure, host-element visits register their spread attributes in a per-walkWeakSetbefore children are walked; only spreads not in that set trigger the old reject path.New auto-memo tests cover admitted shapes (including Topology-style
@forrows and TSXmap), pinned rejections, and a runtime scenario where an unchanged-deps skip preserves DOM/refs/handlers while re-entry updates and clears spread keys. Benchmark ratio notes for svg-dashboard are refreshed; ceilings are unchanged.Reviewed by Cursor Bugbot for commit 241325b. Bugbot is set up for automated code reviews on this repo. Configure here.