Skip to content

perf: reuse universal codec resource-handle factory - #1005

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/reuse-transport-codec-handle-981
Sep 8, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/reuse-transport-codec-handle-981

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

Reuse one root-bound resource-handle factory across universal host prop codec calls. A codec installed after root creation still works, and each call receives a fresh, retainable context snapshot. This is the callback portion of #981's universal transport allocation item.

Why

The transport encoder created a new resource-handle closure for every coded host prop, even though its only captured state belongs to the root. A codec may retain its context or borrow the factory after the encode call, so the factory must remain bound to the originating root.

Changes

  • Create the factory lazily at the first codec call and reuse it for that root's subsequent props and renders.
  • Cover late codec installation, shared factory identity, stable retained contexts, borrowed handles, foreign-root rejection, and recovery in the transport regression.
  • Add an octane patch changeset.

Validation

  • pnpm format:check (not run; changed-file check below)
  • pnpm typecheck
  • pnpm test (not run; targeted suites below)
  • targeted tests: pnpm exec vitest run packages/octane/tests/universal-transport.test.ts packages/octane/tests/universal-renderer.test.ts --reporter=dot (268/268 in development and production); transport-only rerun after the factory identity assertions (54/54)
  • pnpm format:files:check packages/octane/src/universal-core.ts packages/octane/tests/universal-transport.test.ts .changeset/reuse-universal-codec-handle.md; git diff --check; pnpm sync

On the same production source-bundle harness, 256 coded props produced 256 distinct factories per prepare on merged main and one on this branch (one across two prepares). No-codec controls produced zero in both; wire hashes, frozen resource handles, and root stamps matched across five workloads. The full production bundle changed by +68 bytes (797,033 to 797,101). Nine rounds of 400 public root.prepare() calls in both bundle orders gave conflicting timing directions, including in no-codec controls, so no end-to-end throughput gain is claimed.

Risk / follow-ups

This adds one cached callback per codec-using root. The public codec context object remains fresh per prop because codecs may retain its value, host type, and name. Reusing that object would require a separate observable-contract decision; the #981 checklist item stays open.

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

Low Risk
Behavioral contract is unchanged aside from stable factory identity per root; validation and wire encoding paths are covered by expanded transport regression tests.

Overview
Reuses one root-bound createResourceHandle factory for universal host prop codec encoding instead of allocating a new closure on every coded prop.

On first encodeHostProp with a custom codec, the root lazily caches the factory (codecResourceHandle); later encodes pass that same function while each codec call still gets a fresh context snapshot (value, host type, name). That keeps late-installed codecs and codecs that retain context or borrow the factory after encode aligned with the originating root.

Transport tests now cover shared factory identity across props/re-renders, stable retained contexts, borrowed handles, rejection of handles from another root, and recovery on a foreign root.

Reviewed by Cursor Bugbot for commit c0ec99c. 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 8, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 8, 2026 22:28
@domgan-oai
domgan-oai merged commit d97637b into octanejs:main Sep 8, 2026
49 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