Skip to content

perf: inline first context provider cache entry - #1019

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

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

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Store the first resolved context and provider owner inline on each consumer; allocate the existing Map only when a second distinct context is read.
  • Keep provider values live through updates, explicit undefined, default-context reads, hosted owner activation/rebind, conditional reads, and remounts.
  • Add a production browser work gate with zero-, one-, and two-context keyed consumers. Contributes to Track V8 performance audit findings across runtime, SSR, universal core, and compiler output #981; the separate provider-walk has/get work remains open.

Validation

  • pnpm format:check (scoped pnpm format:files:check passed for every changed path)
  • pnpm typecheck
  • pnpm test locally (160 targeted context, host-bridge, JSX, manual-hook, and hydration tests passed in dev and prod compile modes; the full suite passed in current-head CI)
  • pnpm sync (no unrelated tracked diff)
  • node benchmarks/recursive-context/context-cache-work.mjs (production Chromium; baseline/current Map constructions for 512 keyed rows: zero 6/6, one 518/6, two 518/518; update, reorder, and teardown counts unchanged; DOM/identity controls pass)
  • Deliberately broken default-owner recheck and wrong spill owner each failed the new consumer-visible regressions in both compile modes, then passed after restoration.
  • Current-head CI run passed 26/26 jobs on 21ae658a1 (attempt 2 after a Vitest worker failed to run an unrelated SliderTrack test on attempt 1; that file passed locally 30/30). Bugbot passed.

Risk / 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
Touches core readContextFrom / context caching on every use() call and adds a new pointer field on all scopes; behavior is heavily gated but incorrect cache semantics would surface as stale or wrong context values.

Overview
Octane’s use() resolved-provider cache no longer allocates a Map on every consumer’s first context read. The first context key and its provider owner are stored inline on Scope/Block ($$ctxCache + $$ctxCacheOwner); a Map is created only when that consumer reads a second distinct context. Cached entries still point at the owning scope (or the default/bridge sentinel), so values stay live across provider updates, undefined, hosted-owner rebinds, and remounts—hosted roots now drop the cache on rebind instead of calling Map.clear().

Benchmarking and CI gates: the recursive-context suite adds a production Chromium work pass (context-cache-work.mjs, bench:cache) with 512 keyed rows in zero/one/two-context modes. It counts Map constructions (expect 0 extra Maps for single-context mount vs control, 512 for two-context spill) and checks DOM/identity on update, secondary provider, reorder, and unmount; work.mjs runs this after precise coverage.

Tests extend context and react-hosted coverage for multi-context updates, conditional second reads, optional undefined, full root remount, and owner rebinding on a retained root.

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

@domgan-oai
domgan-oai marked this pull request as ready for review September 9, 2026 16:10
@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 merged commit 266302e into octanejs:main Sep 9, 2026
69 of 76 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