Repository navigation
perf: skip context-only parallel use batches - #1018
Merged
domgan-oai merged 1 commit intoSep 9, 2026
Merged
Conversation
Closed
68 of 84 tasks
domgan-oai
marked this pull request as ready for review
September 9, 2026 15:13
14 of 21 tasks
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
Skip compiler-generated
useBatch/puBatchfor runs made entirely of proven module-levelcreateContextreads in TSRX and plain TypeScript. Keep the authoreduse(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
useBatchcalls on mount and full update, including 1,024 redundant context-only calls; partial updates and remounts emitted 94, including 32 redundant calls.Changes
const Context = createContext(...)bindings, with a conservative lexical-shadow guard, in client/server TSRX and plain hook compilation. Only Octane's lexically resolvedusequalifies.Validation
pnpm typecheckpnpm testlocally: 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.pnpm sync, clean generated-file diffRisk / 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
agent-authored)Need help on this PR? Tag
@codesmith-botwith 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/puBatchwhen a run ofuse()calls is made entirely of provably module-levelcreateContextidentities (directconst X = createContext(...)with a conservative lexical-shadow guard). Authoreduse(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 (
emitRunincompile.js) and plain.tshook slotting (emitParallelUseRuninslot-hooks.js), backed by newcontext-use.jsanalysis wired into compile contexts.Benchmark and test coverage tighten the contract:
recursive-context/work.mjsrebuilds unminified production bundles for nameduseBatchcoverage, 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.