Skip to content

perf(octane): lower memo hooks to closure-free caches - #788

Merged
domgan-oai merged 2 commits into
octanejs:mainfrom
openai-oss-forks:codex/closure-free-hook-memo
Aug 19, 2026
Merged

domgan-oai merged 2 commits into
octanejs:mainfrom
openai-oss-forks:codex/closure-free-hook-memo

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Extend production-client memo lowering to safe nested expressions, returned JSX, custom hooks, plain TypeScript modules, and explicit hook slots. Cache hits do not evaluate a factory or callback function expression or dependency-array literal; unsupported cases keep the runtime hook path.
  • Preserve dependency evaluation order, explicit slot sharing, factory scope, TDZ, anonymous function/class names, abrupt completion, and suspension semantics. Flat cache publication now participates in the existing two-way held-transition memo journal.
  • Remove the extra runtime () => callback allocation on client, server, and universal paths. Keep the new compiler/runtime ABI private, with fixed-arity flat publishers to avoid adding ordinary miss-side rest arrays.
  • Add behavioral regressions, a patch changeset, and a deterministic production A/B allocation-and-size benchmark with 12 guards.

Performance evidence

Fresh paired runs against upstream base 922b2d46e reproduce the original pinned-baseline results:

Eligible scenarios Before After
Cache-hit function-expression creations 1,088 0
Cache-hit application array literals 736 0
Cache-hit total array creations 1,824 352
Cache-miss function-expression creations 1,184 448
Compiled fixture gzip bytes 2,169 2,654
Tree-shaken bundle gzip bytes 44,139 44,603

The candidate passes all 12 guards; the base breaches seven. These are source-creation counts, not V8 heap bytes or a browser-latency claim. Bundle cost is +464 gzip bytes (+1.05%) for this corpus. The recorded hookless compiler-throughput control emitted 18 byte-identical outputs; its timing spread includes parity.

Benchmark methodology and source hashes · Design and safety boundaries

Validation

  • pnpm sync — completed on the rebased tree; no generated changes remained. Used the available cached dependencies with pnpm_config_verify_deps_before_run=warn.
  • pnpm format:check — repo-wide check not run; scoped Prettier check passed for all 33 non-ignored changed files, and git diff --check passed.
  • pnpm typecheck — repo-wide check not run; tsgo --noEmit -p packages/octane/tsconfig.json and tsgo --noEmit -p packages/octane/typetests/tsconfig.json passed. The added hooks/transition fixtures introduce zero diagnostics relative to their baseline.
  • pnpm test — normal locked-toolchain run remains unavailable because dependency installation returned registry 403.
  • Targeted tests: actual Vitest with the checked-in JavaScript parser, frozen AST/location assertions, and real Octane plugin/runtime. Rebased dev/HMR matrix: 305 passed across 14 files. Rebased production core run: 7,164 passed, with the same ten baseline/dependency failures and three suite-load failures described below.
  • node benchmarks/bench.mjs --ratios hook-memo with the same documented fallback loader for both sides — 12/12 pass; baseline negative control fails seven. Observer tests: 2/2 pass.

Fallback toolchain: Node 26.4.0, @tsrx/core 0.1.56, esrap 2.3.0, esbuild 0.28.1. The ten remaining test failures are four known Volar/core-version mismatches, three installed-binding discovery failures, and three native compiler-registration failures. The imperative-DOM differential fixture, production-profile bundle, and React-hosted web3 suites cannot load because the fallback setup lacks their generated fixture/native parser/workspace dependencies. These are not claimed green.

Risk / follow-ups

  • Rerun the normal locked native-parser and full workspace checks before marking this ready. This PR intentionally remains a draft.
  • Generated code grows; the committed ratio guards cover the paired fixture and bundle costs. A representative production-browser workload is still needed for any latency or GC claim.
  • A pre-existing continuing-transition limitation remains: after promotion suspends again, an urgent render can retain an empty-dependency callback from the attempt. Both ordinary and lowered memo paths reproduce it; the separate scheduler fix is documented, not folded into this optimization.

Provenance

  • An agent produced this diff (agent-authored)

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


Note

High Risk
Touches core compiler output, client hook runtime, and transition memo journaling; incorrect lowering could change identities, TDZ, or held-transition behavior despite broad tests and benchmarks.

Overview
Production client compilation now lowers more useMemo / useCallback sites to closure-free inline caches instead of per-render factory arrows and dependency arrays. Eligible cache hits skip evaluating the factory and skip creating dependency-array literals; useCallback only materializes its function on a miss. Coverage expands beyond flat declarations to nested expressions, returned JSX, custom hooks, plain .ts/.js hook modules, and explicit third-slot calls, with unsafe shapes still on the runtime hook path.

The compiler adds a path-aware post-slot pass (inline-hook-memo.js, plain-hook-memo.js) for helpers and explicit slots, plus flat per-body _k$N caches for render-local sites. Runtime gains private helpers (hookMemoPublish*, memoTake* / memoPublish*, hookMemoCreate, hookMemoEqual) and stores callback values directly—no extra () => fn wrapper. Held-transition rollback/promotion journals inline memo cell ranges alongside hook-map entries.

A new hook-memo benchmark (fixtures, post-tree-shake allocation observer, 12 ratio guards) and MCP octane_benchmark listing document the allocation and gzip tradeoffs (~+1% bundle gzip in the recorded corpus).

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 19, 2026
@trueadm
trueadm marked this pull request as ready for review August 19, 2026 11:07
@domgan-oai
domgan-oai merged commit 489a886 into octanejs:main Aug 19, 2026
24 of 25 checks passed
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 perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant