Skip to content

perf: specialize zero-argument errors - #1362

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/fix-error-bundle
Sep 28, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/fix-error-bundle

Conversation

@domgan-oai

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

Copy link
Copy Markdown
Contributor

Summary

  • Specialize catalog-backed, zero-argument errors in published runtime modules so small consumers can avoid the general error formatter and argument encoder.
  • Preserve development and production messages and the call-time environment lookup. Modules with mixed or unsupported formatter uses keep the existing implementation.

Why

A binding-only consumer can retain the formatter for parameterized errors even though its own errors have no arguments. Specializing those calls removes that unnecessary dependency from the consumer's production bundle.

Changes

  • Apply a conservative, catalog-validated build transform to the ESM and CommonJS outputs.
  • Add message-contract, unsupported-input, published-output, and production-bundle regression coverage.
  • Add an Octane patch changeset.

Validation

  • Clean frozen dependency installation and full pnpm sync — not completed.
  • pnpm format:check
  • pnpm typecheck
  • pnpm test
  • Focused checks run before opening the PR: transformer tests (4), CommonJS packaging tests (10), error-catalog tests (5), and published-output tests (2) passed. A scratch-packed consumer passed ESM and CommonJS message checks.
  • These focused checks used a separately prepared toolchain and source-normalized package carrier, not the repository's complete locked dependency installation. The production-bundle assertion was also checked against the unmodified build and failed there as expected.

In a public production binding fixture, the built bundle decreased by 86 gzip bytes. A mixed binding/runtime fixture increased by 75 gzip bytes and a full-runtime fixture by 172 gzip bytes; the optimization is scoped to dependency elision, not a universal size reduction.

Risk / follow-ups

  • This draft still needs a clean dependency installation, successful repository sync, and the usual validation.
  • The existing process.env.NODE_ENV behavior is unchanged. In environments that neither provide process nor replace the expression, an error path can still raise a ReferenceError; standalone-browser support is separate work.

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
Published runtime JS and error strings are rewritten at build time; behavior is guarded by conservative AST checks and tests, but any transform bug would affect production error messages and consumer bundle graphs.

Overview
Adds a publish-time esbuild transform that rewrites Octane runtime modules whose only formatter usage is catalog-backed, literal zero-argument formatClientError / formatServerError calls. Those modules stop importing the generated formatter: development still returns full catalog strings via process.env.NODE_ENV, and production uses a tiny inlined __octaneNoArgError helper for minified messages. Mixed, parameterized, aliased, or otherwise unsafe patterns are left unchanged.

The plugin runs on both ESM and CommonJS dist builds (build.mjs, buildPackageCommonjs plugins forwarding), and the Octane build now runs published-errors.test.mjs to lock message contracts and assert binding-only production bundles no longer retain error-codes.*.generated / error-message (or encodeURIComponent). Unit coverage lives in specialize-error-calls.test.mjs. Patch changeset for octane.

Reviewed by Cursor Bugbot for commit 284f8d6. 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 28, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 28, 2026 12:39
@trueadm
trueadm merged commit 010c88c into octanejs:main Sep 28, 2026
49 checks passed
trueadm added a commit that referenced this pull request Oct 7, 2026
…gument errors (#1856)

The publish-time error specialization inlined a private __octaneNoArgError
helper, carrying the full "Minified Octane error" text, into each of the 29
modules it rewrote. A consumer bundle carried one copy per such module, and
a code-split application one in every chunk that included any of them.

Rewritten modules now import formatNoArgumentErrorMessage from the new
import-free src/error-message-no-arguments.ts. Messages, the call-time
NODE_ENV read and #1362's binding-only contract (no generic formatter, no
argument encoder) are unchanged. error-message.ts is untouched, so
source-built bundles are byte-identical.

Published dist, hydrating signals app: 9 copies -> 2 (-1,357 raw); split
into 19 chunks: 22 copies in 10 chunks -> 2 in one (-3,662 raw, -1,105 gzip).

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants