Skip to content

perf: avoid cause-free Error serialization overhead - #194

Merged
steipete merged 1 commit into
mainfrom
claude/perf-error-cause-v16
Oct 20, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/perf-error-cause-v16

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown

Cause-free Error serialization now keeps the terminal fast path and exact v14 record layout, while preserving the Error.cause semantics added in #192.

Design

Only an Error with an own data cause uses the new ErrorInstanceWithCauseTag and nonterminal graph traversal. Its cause is captured and rooted before metadata getters run, and object pooling preserves aliases and self-cycles. Ordinary own properties use JSC's direct storage and attributes; unusual native/custom property cases retain descriptor lookup. Serialization never restarts or replays getters.

The first cause-bearing record patches the fixed-width stream header to v16 without moving bytes. Cause-free graphs remain byte-identical v14, with no presence bytes, offset bookkeeping, or compaction. Readers accept formats through v14 and v16; they reject v15, an unreleased intermediate layout. Advanced IPC advertises a new v16 capability bit, separate from #192's v15 bit. Peers advertising only the old bit, or no bit, receive v14 with causes omitted.

Performance and attribution

The unchanged payload benchmark used ten alternating pairs and optimized Linux x64 builds. S3 is ef37c31de3, #192 main is cb98044b7d, and this change is 5af8df187. Error payloads contain one Error without a cause: 273 serialized bytes, or 307 bytes with the message wrapper. Worker timings are amortized send/drain costs, not synchronous call latency.

Error payload operation #192 / S3, original gate This change / S3, first qualification This change / S3, later interleaved control
structuredClone 1.039 1.026 1.020
Worker postMessage 1.073 1.042 1.020

Absolute medians from the later control:

Error payload operation S3 This change Added cost
structuredClone 1.882 µs 1.911 µs ~29 ns
Worker postMessage 3.882 µs 4.029 µs ~147 ns

Ratios are medians of paired ratios; absolute values are separate medians, so their quotient need not equal the paired ratio. The original gate and later control are distinct runs. The first qualification still exceeded the 1.01 target and the 1.03 Worker gate; neither run passed every per-case gate, and the limits were not relaxed or reported as passing. This residual cost is accepted as a documented tradeoff for Node-parity Error.cause semantics.

The original profiles identified duplicate terminal/StateUnknown dispatch and descriptor work; compaction accounted for only a negligible sampled share. Ablation showed that removing cause support alone did not recover clone performance, while restoring S3's source-level Error metadata writer did. The Worker residual was not isolated to a single function. Ordinary Worker messages do not enable the transport Buffer envelope or execute the uncaught-worker Error metadata path. A separate cause-bearing ten-pair comparison measured 0.990× main for cloning and 1.025× for messaging (informational).

On Apple silicon, three interleaved native-arm64 spot checks with matched no-LTO builds showed Error-clone medians at parity with S3 (2.479 µs S3; 2.475 µs candidate) and no observed Error Worker regression (3.578 µs S3; 2.562 µs candidate). Candidate medians also remained ahead of Node 26.12.0 (2.495 µs clone; 3.111 µs Worker). This host was noisy, so these checks support parity rather than a precise speedup claim.

Compatibility and validation

  • 10/10 golden v14 byte hashes matched, including Buffer envelopes.
  • 54/54 IPC cells passed across S3, fix: preserve Error cause graphs with compatible IPC serialization #192 main and v16 in both directions. v16/v16 preserves causes; v16/legacy pairs omit them. The immutable main/main control retains its own v15 causes.
  • 18/18 direct-wire cells passed: v14 interoperates, and v15/v16 reject each other's cause-bearing streams cleanly.
  • Four cause value kinds plus the self-cycle matched Node 26.3.0; all eight portable cause tests passed on Node and candidate.
  • 106 focused clone/wire tests passed, with 7,709 assertions covering snapshot ordering, aliases, cycles, dictionary/accessor behavior and mixed tags; raw IPC capability test passed.
  • The unchanged 50-file native parity selection ran against candidate and fork main: both passed 49 files and failed the same worker builtin-alias error-text assertion, with no new failure. All structured-clone files, all four v8 files and both selected worker-thread files passed. The broader Web Worker selection passed 15/16 on both; worker-entry-point.test.ts expected a builtin-entry-point error but received ModuleNotFound for #fs. This existing baseline failure is retained, not reported as green.
  • Exact-head CI is green: Linux x64 and Darwin arm64, Rust, source lints, JS lint, format. The PR merge commit's tree is identical to 5af8df187.
  • The final independent Codex P2 review of this unchanged head is scoped-clean, following the earlier clean reviews.

Upstream: oven-sh#31525 addresses Error cause preservation; this builds on #192 while retaining the v14 terminal path and introducing independent v16 negotiation.

Retain terminal v14 Error records and snapshot own data causes for a distinct v16 tag. Negotiate v16 support separately from the intermediate v15 format so older IPC peers continue receiving v14 messages.
@steipete
steipete marked this pull request as ready for review October 20, 2026 17:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T18:01:05.100882Z 5af8df1 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete merged commit b40c6ae into main Oct 20, 2026
12 checks passed
@steipete
steipete deleted the claude/perf-error-cause-v16 branch October 20, 2026 18:01
steipete added a commit that referenced this pull request Oct 24, 2026
…ral design (#196)

This reverts b40c6ae (#194), then
cb98044 (#192), using git revert.

The pooled median Worker session-message ratio across three machines was
1.078019079 against the predeclared maximum 1.05. Restore the S3 v14 wire
format and Error cause omission pending a performance-neutral design.

Keep #195's pending-container-terminator reservation unchanged. The source
tree differs from S3 only by that serializer patch and the changelog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant