Skip to content

Inline hook-memo tier: de-callback useMemo/useCallback + parallel-use creations, memoize use()-fed promise chains - #208

Merged
trueadm merged 6 commits into
mainfrom
inline-hook-memo-tier
Jul 21, 2026
Merged

trueadm merged 6 commits into
mainfrom
inline-hook-memo-tier

Conversation

@trueadm

@trueadm trueadm commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

What

Production client compiles lower the hook memo tier from runtime-callback form to inline caches, and a new taint pass closes the use()-fed promise-chain hole. Design doc: docs/decallback-memo.md.

1. Authored/auto-generated useMemo/useCallback → inline cell regions. const x = useMemo(fn, deps) declarations in proven render-scope bodies compile to inline regions over a per-body flat cell array (__s.slots._k$N — a named expando, so the slots array keeps its packed elements kind). Zero allocations on a dependency hit (no factory closure, no deps array, no hooks-map lookup), Object.is compares (React NaN/±0 parity), closures allocated only on a miss, block bodies inlined with labeled-break early returns, explicit-null deps evaluated inline with no cache. Cells publish immediately (unlike autoMemo's transactional cache), value-before-deps, so promise identity survives suspend-replay and a throwing factory leaves the previous entry fully usable.

2. Parallel-use() creations → closure-free puTake/puPub ABI. Pass A creations keep their Symbol-slot scope.hooks entries — warm adoption, activeMemoMatch dedup, and episode stamping are preserved exactly — but the per-render arrow + deps-array allocations are gone (arity-specialized puTake0..4, deps array built only on cold branches). __warm plans keep their closure form (suspension-only). Fully-lowered modules carry no dead _$useMemo import.

3. Pass A′ — use()-fed const chain memoization (client AND SSR). The natural authoring shape

const userPromise = fetchUser(id);
const thumbnailPromise = userPromise.then((u) => u.thumbnail());
return <ThumbnailRenderer thumbnail={use(thumbnailPromise)} />;

previously memoized nothing (trivial identifier argument): every render and every suspend-replay re-ran fetchUser — the replay leniency drops the fresh promise but the duplicate request already fired — and the chain was invisible to __warm. A taint pre-pass marks local consts transitively feeding any use() argument and memoizes each creation-bearing tainted const at its declaration with the same slot-keyed machinery as Pass A. Each link keys on its real inputs (userPromise → [fetchUser, id], warmable; thumbnailPromise → [userPromise]).

Dev/HMR/profile, server, universal units, custom-hook-context bodies, and ineligible shapes keep the runtime forms. inlineHookMemo: false is a diagnostic escape hatch (like autoMemo: false).

Review findings that shaped the implementation

  • .then member-dep trap: the one-level member-path dep policy would give a derived chain dep userPromise.then — Promise.prototype.then, identical across every promise — pinning it permanently stale when its upstream changes. Member deps rooted at any body-local binding now coarsen to the local's identity; params keep precise paths (props.id). Behaviorally pinned via a reassigned-let upstream fixture.
  • Universal pipeline runs Pass A at a different site and never reaches the lowering pass — the deferred _$useMemo import registration is an explicit per-pipeline flag; universal stays eager and on runtime forms.
  • Per-declaration chain memos rather than React Compiler's single-region collapse: substituting an init across statements could move its evaluation past interleaved side effects.

Validation

  • Full suite: 1258 files / 12,006 tests green, including the octane-prod project (the inline branch's coverage) and SSR/hydration/differential suites. pnpm typecheck, pnpm format:check clean.
  • New behavioral suites run under BOTH vitest projects with identical expectations (runtime path vs inline path — the semantic-equivalence proof): recompute policy, NaN deps, conditional sites, early returns, null-deps identity, callback staleness, memo-across-suspension, and the verbatim originating chain shape (exactly one fetchUser and one thumbnail() call across mount + both replay waves). The chain tests fail 8/8 with Pass A′ disabled.
  • Benches vs same-day baseline (same command/machine): memo-wall 1–4% faster across ops; todomvc noise-level; codegen-size +2.2% gz(min) (24,555→25,096 — the inline-region expansion cost); bundle-size and async-composition/async-waterfall ratio guards pass (exact-count semantic probes unchanged: waves/calls identical).

Residual risk / follow-ups

  • Universal-renderer bodies and directive-arm-scoped authored memos stay on the runtime path (documented); Pass A′ skips let chains (unsound to taint — covered by a test proving they're never staler than today) and arm-scoped consts.
  • Server chain shape is pinned at source level (puMemo wrapping + coarsened deps); no SSR behavioral rig exists for it yet beyond the existing ssr-parallel-use suites.
  • Possible follow-up: import-aware dep pruning (RC drops stable module imports like fetchUser from deps; we conservatively keep them).

🤖 Generated with Claude Code


Note

High Risk
Large compiler/runtime changes to hooks, Suspense memoization, and warm-plan behavior; subtle stale-data risk around dependency coarsening and suspend-replay is mitigated by dual-project tests but SSR chain behavior is mostly codegen-pinned.

Overview
Production client compiles add an inline hook-memo tier (docs/decallback-memo.md): eligible useMemo/useCallback declarations become flat _k$N cell regions on __s.slots (dependency hits avoid factory closures, deps arrays, and hook-map lookups), while parallel-use() Pass A sites lower to puTake0–4 / puPub so Symbol slots stay warm-visible without per-render memo closures. Dev/HMR/profile, server, universal units, and declined shapes keep runtime hooks; inlineHookMemo: false bisects the new path.

Pass A′ runs before parallel Pass A on client and SSR: a taint pass memoizes setup const creations that feed use() (including .then chains), with member deps on body locals coarsened to promise identity so derived links do not pin on Promise.prototype.then. Chain heads join __warm; shadowed/param-colliding names are excluded. Parallel Pass B gains better else if / braceless use() arm handling.

New puMiss / puTake* / puPub runtime ABI mirrors useMemo warm semantics on cache hits. Docs, README, and agent rules document promise-in-render and inline memo behavior; behavioral tests run under both octane and octane-prod.

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

… creations, memoize use()-fed promise chains

Production client compiles lower the hook memo tier from runtime-callback
form to inline caches (docs/decallback-memo.md):

- Authored/auto-generated `const x = useMemo/useCallback(fn, deps)`
  declarations become inline regions over a per-body flat cell array
  (`__s.slots._k$N`): zero allocations on a dependency hit, Object.is
  compares, closures only on a miss, labeled-break early returns,
  immediate publish so promise identity survives suspend-replay and a
  throwing factory keeps the previous entry.
- Pass A parallel-use creations lower to an arity-specialized
  puTake0..4/puPub/puMiss runtime ABI that preserves every warm-plan
  semantic (Symbol-slot hooks-map entries, adoption, episode stamping,
  activeMemoMatch dedup) while eliminating the per-render arrow +
  deps-array allocations; fully-lowered modules carry no dead
  _$useMemo import.
- New Pass A′ (client AND SSR pipelines): local const promise chains
  that transitively feed a use() argument are memoized at their
  declarations, so the natural `const p = fetchUser(id); const t =
  p.then(…); use(t)` shape no longer refetches per replay or
  re-render, and the chain head joins the __warm prefetch plan.
  Member deps rooted at body-locals coarsen to the local's identity
  (`p.then` is Promise.prototype.then — identical across promises —
  and would pin a derived chain stale forever).

Dev/HMR/profile, server, universal units, and ineligible shapes keep
the runtime forms; `inlineHookMemo: false` is a diagnostic escape
hatch. Behavioral equivalence is proven by running the new
inline-hook-memo / use-chain-memo suites under both vitest projects
(runtime path vs inline path, identical expectations); the chain
tests fail 8/8 with Pass A′ disabled.

Full suite 12,006 tests green; memo-wall improves 1-4%; codegen-size
+2% gz(min) (inline-region expansion); bundle-size and
async-composition/waterfall ratio guards pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview, Comment Jul 20, 2026 11:21pm
octane-website-mcp Ready Ready Preview, Comment Jul 20, 2026 11:21pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 20, 2026 21:41 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 20, 2026 21:41 Inactive
Comment thread packages/octane/src/compiler/compile.js Resolved
…y consts

Bugbot finding on #208: collectUseArgumentRoots resolved each use()
argument's free identifiers against an empty bound set while walking
into nested functions and directive arms, so a shadowing inner binding
(a @for item, a nested arrow param/local) seeded its NAME and an
unrelated same-named body const could be wrongly memoized — freezing a
creation the component expects to re-run every render.

The seed scan is now scope-aware: names bound by any scope the
candidate collector cannot reach are bound out before seeding — nested
function params + internal declarations, loop bindings (including
JSXForExpression item/index, scoping key + body but not the iterable
or @empty arm), catch params, and every block's declarations inside
the render tree (arm consts are never setup candidates). JSX reached
at a setup value position flips into render-tree binding rules.
Over-binding is the safe direction: a dropped seed leaves that chain
unmemoized — exactly today's behavior.

Pinned behaviorally (ShadowedLoopHost: a @for arm's use(item.promise)
must not stop the body's `const item = build()` recreating per
render) and probed in both directions (an outer const use()d from
inside an arm still seeds). Full suite 12,010 tests green.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 20, 2026 21:59 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 20, 2026 22:00 Inactive
…README, website docs, llms.txt)

The user-observable half of the inline hook-memo tier deserves public
documentation: promises created during render — including local .then
chains feeding use() — are now a SUPPORTED authoring pattern (no
cache() wrapper, stable across re-renders and suspense replays,
refetching exactly when inputs change), and production useMemo/
useCallback compile to allocation-free inline caches.

- website/differences-from-react: extends the parallel-use section
  with the chain example, the dependency-keying story, and the React /
  React Compiler contrast.
- README "At a glance": inline-cache note on the hook-API bullet plus
  a "Promises in render are safe" bullet.
- llms.txt: agent-facing directives — don't add cache(), don't hoist
  fetches to effects, don't hand-restructure waterfalls; plus the
  transparent inline-cache note under dependency-taking hooks.

Website tests (mdx compile + e2e) and the react-parity audit pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 20, 2026 22:12 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 20, 2026 22:12 Inactive
Comment thread packages/octane/src/compiler/compile.js Resolved
Comment thread packages/octane/src/compiler/compile.js Resolved
…ainting

Two Bugbot findings on #208:

- collectCandidates/rewriteStatements only entered IfStatement
  alternates that were blocks, so chain consts in `else if` arms were
  never memoized (recreating every render and replay — the hole the
  pass exists to close). Both walkers now recurse IfStatement
  alternates with the guard chain extended (!outerTest, innerTest),
  matching the lowering pass's existing else-if handling.

- Tainting is name-based, and setup-level if/block declarations are
  legitimate candidates, so `use(x)` against an inner `const x` also
  tainted an unrelated outer `const x` — freezing a creation that
  must recreate per render (the same failure mode as the @for
  shadowing fix, through setup scopes). Any name declared more than
  once in the walked setup region, or colliding with a component
  param, is now excluded from tainting and memoization entirely:
  which binding a seed means is unknowable by name, and exclusion is
  never staler than today's recreate-per-render behavior. Shadowed
  names don't cascade taint either; a downstream unique-named link
  still memoizes, coarsening its dep to the in-scope local's
  identity.

Behaviorally pinned: BranchChainHost (else-if chain fetches once
across the suspend replay) and SetupShadowHost (a setup-block shadow
must not stop the outer `const item = build()` recreating). Full
suite 12,014 tests green.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 20, 2026 22:24 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 20, 2026 22:25 Inactive
Comment thread packages/octane/src/compiler/compile.js Resolved
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 20, 2026 22:56 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 20, 2026 22:57 Inactive

@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 is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 06ca22d. Configure here.

Comment thread packages/octane/src/compiler/compile.js Resolved
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 20, 2026 23:20 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 20, 2026 23:21 Inactive
@trueadm
trueadm merged commit 6cecb47 into main Jul 21, 2026
22 checks passed
@trueadm
trueadm deleted the inline-hook-memo-tier branch July 21, 2026 00:08
mrdiyorbek-juraev added a commit to mrdiyorbek-juraev/octane that referenced this pull request Jul 21, 2026
Brings in 5 upstream commits: the safe inline-script content contract
(octanejs#215), the tanstack.com shell port (octanejs#214), the TSRX directive arm output
docs (octanejs#213), the inline hook-memo tier (octanejs#208), and the website menu /
scroll-spy work (octanejs#209). Upstream added three bindings
(tanstack-router-ssr-query, tanstack-hotkeys, tanstack-pacer), taking the
table to 39.

Six conflicts, all resolved as unions so neither side lost content:

- website/src/content/bindings.json — @octanejs/cmdk listed alongside
  upstream's three new bindings; the "UI and interaction" description
  keeps command menus and gains keyboard shortcuts and event pacing.
- website/public/llms.txt — same union in prose form.
- docs/bindings-status.md, docs/packages.md, docs/binding-parity-gaps.md
  and the evals user-apps-v1 manifest are generated, so they were taken
  from upstream and regenerated (39 bindings, 48 publishable packages,
  0 parity pins, 19 eval tasks).

packages/cmdk is byte-identical to its pre-merge state; upstream's
compiler changes do not perturb it. Verified: 32/32 cmdk and cmdk-ssr
tests including both differential parity checks against [email protected],
tsrx-tsc and tsgo clean, prettier clean, and all five freshness gates
current.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

This branch was previously deployed

2 inactive deployments
Preview – octane-website — 788145d3 Deployed Jul 20, 2026 by vercel[bot]
Preview – octane-website-mcp — 788145d3 Deployed Jul 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant