Skip to content

perf: avoid cycle set for primitive transport props - #1004

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

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/lazy-transport-seen-981

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Allocate cycle-tracking state only when a transported host value is an object; primitive props now return before the WeakSet is created.
  • Cover both the codec and plain transport paths with mixed primitive props, nested shared values, clone isolation, and cycle rejection.

Why

The universal renderer clones every transported host prop. The default argument to cloneSerializableValue allocated a WeakSet even when a value was null, undefined, a string, number, bigint, or boolean. This is the primitive-allocation part of #981.

Changes

  • Make the cycle set optional at entry and initialize it after object and resource checks. Recursive object visits share the same set, and the existing finally still removes each visited object.
  • Add a consumer-level transport regression across both codec modes. Deliberately retaining visited objects makes all four new development/production cases fail when a repeated shared object is encountered; restoring the implementation makes them pass.
  • Add an octane patch changeset.

Validation

  • pnpm format:files:check packages/octane/src/universal-core.ts packages/octane/tests/universal-transport.test.ts .changeset/lazy-transport-cycle-tracking.md
  • pnpm typecheck (passed locally)
  • pnpm test (full suite left to CI)
  • pnpm exec vitest run packages/octane/tests/universal-transport.test.ts packages/octane/tests/universal-renderer.test.ts --reporter=dot — 266 passed across development and production projects.
  • pnpm typecheck:files packages/octane/src/universal-core.ts; pnpm sync; git diff --check.

Production source-bundle ABBA probe on Node 26.4.0/V8 (baseline ab3236409, same build inputs): an exact-source serializer probe over 15 rounds × 250,000 primitive calls measured median 0.01773 → 0.00882 µs/call, with nonoverlapping observed ranges. The object-valued control ranges overlapped. Instrumentation counted 256 → 0 WeakSet allocations for a 256-primitive-prop transported prepare; object props remained 256 → 256 and local props 0 → 0. Across nine paired public-renderer runs × 700 prepares, the 256-primitive-prop median was 0.06491 → 0.06122 ms, but ranges overlapped, so the end-to-end timing is inconclusive. Command SHA-256 hashes matched for all three workloads; nested clones remained distinct and frozen.

Current-head CI passed all 26 jobs on attempt 2 at da4c63803985b09be7e26b21e94601a88e958b92, including parity, package validation, browser integration, and provenance. Attempt 1 could not run a Base UI drawer test file in the broad parity shard; that file passed all 16 tests in a focused adapted-project run, and the same-head parity shard passed on retry. Cursor Bugbot passed without comments.

Risk / follow-ups

The change only affects transported serialization. Object cycle and sharing semantics remain protected by the same recursion set; the test covers both codec modes and rejected updates. The #981 item also calls out the codec context object and closure per prop; that part remains for a separate measured change.

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
Serialization behavior for objects is unchanged; only avoids allocations on the primitive fast path, with new transport tests covering both codec modes.

Overview
Lazy cycle tracking for universal host values sent across a transport: cloneSerializableValue no longer creates a WeakSet on every call—primitives (null, undefined, strings, numbers, bigints, booleans) return immediately, and the set is created only when cloning object graphs (same sharing/cycle rules as before).

Adds a transport test (codec on/off) that exercises mixed primitives, nested shared references, frozen clone isolation, and cycle rejection. Includes an octane patch changeset.

Reviewed by Cursor Bugbot for commit da4c638. 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 21:47
@domgan-oai
domgan-oai merged commit 12ea12a into octanejs:main Sep 8, 2026
76 of 80 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