Skip to content

perf: skip context-only parallel use batches - #1018

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/context-only-use-batch-981
Sep 9, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/context-only-use-batch-981

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Skip compiler-generated useBatch/puBatch for runs made entirely of proven module-level createContext reads in TSRX and plain TypeScript. Keep the authored use(Context) calls, mixed promise batches, and the first applicable child warm plan. Advances #981.

Why

A recursive context workload emitted one context-only batch per leaf render. The production browser work gate measured 3,072 useBatch calls on mount and full update, including 1,024 redundant context-only calls; partial updates and remounts emitted 94, including 32 redundant calls.

Changes

  • Prove direct module const Context = createContext(...) bindings, with a conservative lexical-shadow guard, in client/server TSRX and plain hook compilation. Only Octane's lexically resolved use qualifies.
  • Preserve batching for promises and mixed reads, plus the trailing registration that warms async descendants of context-only parents.
  • Add consumer behavior coverage for provider changes, dynamic and shadowed reads, pending siblings, mixed promises, and SSR hydration. The deterministic benchmark now gates browser batch counts and plain TypeScript client/server output.
  • Repair the browser work gate's named-call attribution by rebuilding diagnostic production bundles without minification after the timed pass.

Validation

  • Scoped Prettier check on changed files
  • pnpm typecheck
  • pnpm test locally: the repository-wide run reached a Chromium MachPort sandbox denial; the isolated browser test passed with browser permission. Current-head CI passed on attempt 3.
  • Targeted Vitest context, parallel-use, and SSR suites (development and production)
  • Recursive-context Chromium precise-call gate: TSRX 3,072→2,048 full-render batch calls and 94→62 partial-render calls; exact 1,024/32 text-write controls unchanged. Plain TypeScript client/server context-only output has zero batch calls; mixed promise control retains one.
  • pnpm sync, clean generated-file diff
  • Current-head CI: 28 passing checks, six expected skips, no pending or failed checks; Bugbot passed. Two unrelated 5-second test timeouts in earlier attempts passed on rerun without code changes.

Risk / follow-ups

The proof deliberately leaves imported, dynamically selected, and lexically shadowed contexts on the existing batch path. Other unchecked #981 items remain separate follow-ups.

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

Medium Risk
Changes parallel-use() codegen in client and server compilers; the proof is intentionally narrow (shadow/import/dynamic reads stay batched) but incorrect analysis could affect suspense/warming behavior.

Overview
The compiler stops emitting parallel useBatch/puBatch when a run of use() calls is made entirely of provably module-level createContext identities (direct const X = createContext(...) with a conservative lexical-shadow guard). Authored use(Context) stays in place; promise reads, mixed context+async runs, dynamically selected contexts, and shadowed names still go through batching, including the trailing child warm registration.

This lands in both TSRX (emitRun in compile.js) and plain .ts hook slotting (emitParallelUseRun in slot-hooks.js), backed by new context-use.js analysis wired into compile contexts.

Benchmark and test coverage tighten the contract: recursive-context/work.mjs rebuilds unminified production bundles for named useBatch coverage, adds exact batch-count gates (e.g. TSRX mount/root 3072→2048, partial/remount 94→62), and AST-checks plain hooks for zero vs one batch call. New context fixture scenarios cover custom hooks, dynamic context selection, pending siblings, mixed promises, shadowed locals, and SSR hydration.

Reviewed by Cursor Bugbot for commit 19c404f. 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 Sep 9, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 9, 2026 15:13
@domgan-oai
domgan-oai merged commit 70c29ab into octanejs:main Sep 9, 2026
94 of 102 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