Skip to content

perf(cli): compile the CLI with bytecode - #6708

Merged
jgoux merged 2 commits into
perf/stack-managed-snapshotsfrom
perf/cli-compile-bytecode
Sep 23, 2026
Merged

jgoux merged 2 commits into
perf/stack-managed-snapshotsfrom
perf/cli-compile-bytecode

Conversation

@avallete

@avallete avallete commented Sep 22, 2026

Copy link
Copy Markdown
Member

Compiled CLI builds now enable minification, ESM, and bytecode at depth 2 to reduce startup work. Release, local, and E2E binaries share the same compilation options, including the local npm release workflow.

Depth 2 limits the binary-size cost compared with compiling all nested functions ahead of time.

Minify, ESM, and bytecode depth 2 shorten compiled startup for local binaries and release builds.
@avallete
avallete added this pull request to stack #6711 September 22, 2026 14:26
@avallete
avallete marked this pull request as ready for review September 22, 2026 14:26
@avallete
avallete requested a review from a team as a code owner September 22, 2026 14:26

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

Only Claude’s independent review was available; Codex’s pass did not complete. After verification against the PR code, trusted conventions, and pinned Bun 1.4.1 behavior, three correctness concerns are refuted and six documentation/maintainability nits are confirmed. No blocking defect was verified.

Findings

Severity Location Category Sources Claim
⚪ NIT apps/cli/scripts/build.ts:124 maintainability claude The helper’s merge order forces shared flags over caller configuration while callers still redundantly specify minify: true, obscuring which layer owns those settings.
⚪ NIT apps/cli/scripts/bundle-externals.ts:11 documentation claude The new compile-flags declaration separates the opening oxfmt documentation from the externals constant it describes.
⚪ NIT tools/release/local-release.ts:194 duplication claude The shell-based local release duplicates the shared bytecode settings as CLI literals, allowing its configuration to drift from the object-API builds.
⚪ NIT apps/cli/scripts/bundle-externals.ts:8 naming claude The compiledBytecode name and “published CLI binary” documentation understate the object’s scope and consumers.
⚪ NIT apps/cli/scripts/build-binary.ts:24 developer-experience claude The local/E2E binary is now minified and bytecode-compiled without documenting the developer-experience trade-off.
⚪ NIT docs/adr/0011-cli-release-and-distribution-strategy.md:48 documentation claude The packaging ADR’s illustrative compile command omits the newly required bytecode depth and ESM settings.

Findings outside the diff

  • ⚪ NIT docs/adr/0011-cli-release-and-distribution-strategy.md:48 — The packaging ADR’s illustrative compile command omits the newly required bytecode depth and ESM settings.
Refuted findings (kept for transparency, not posted as review comments)
  • apps/cli/scripts/bundle-externals.ts:14 (build-config): bytecodeDepth may be ignored by Bun’s object API, causing release build paths to use different bytecode depths.
    Refuted: Pinned Bun 1.4.1 explicitly recognizes and validates the object-API property: a string value reports that bytecodeDepth must be a number, negative and fractional values receive range/type errors, and the valid configuration proceeds to executable output. The missing bun-types declaration does not mean the runtime ignores the property.
  • apps/cli/scripts/bundle-externals.ts:15 (build-config): Combining bytecode with ESM may be unsupported or silently disable bytecode, leaving the optimization ineffective.
    Refuted: Bun 1.4.1 explicitly reports that ESM bytecode requires compile: true; both affected object-API builds supply that option. The exact valid combination is accepted and reaches executable generation, so the cited historical CJS restriction does not apply to the pinned runtime.
  • apps/cli/scripts/build-binary.ts:24 (release-risk): The PR switches compiled binaries from CJS to ESM, potentially breaking injected require behavior without cross-platform validation.
    Refuted: The prior build had no bytecode flag and Bun 1.4.1 defaults such builds to ESM, so this does not switch the binary from CJS to ESM. Moreover, .github/workflows/build-cli-artifacts.yml:109-118 builds every target before publication, and release smoke tests execute Linux glibc/musl artifacts on both architectures plus native Windows and macOS artifacts. Some platform/command coverage gaps remain, but not the claimed format regression.

Stats

Claude findings: 9 · Codex findings: 0 · Confirmed: 6 · Refuted: 3 · Uncertain: 0


Models: claude-opus-5 + gpt-5.6-sol · Trigger: auto · Workflow run

This review runs once per PR. A maintainer can request another with a /ai-review comment.

Comment thread apps/cli/scripts/build.ts Outdated
Comment thread apps/cli/scripts/bundle-externals.ts Outdated
Comment thread tools/release/local-release.ts Outdated
Comment thread apps/cli/scripts/bundle-externals.ts Outdated
Comment thread apps/cli/scripts/build-binary.ts Outdated
@jgoux

jgoux commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Triaged the AI review and addressed all six confirmed nits, including the release ADR example mentioned outside the inline diff. Build paths now share compileOptions; local release consumes the same object through Bun.build, and the redundant flags and displaced documentation are cleaned up.

The three previously refuted correctness concerns remain refuted: the pinned Bun accepts the depth option and ESM bytecode, and this does not introduce a CJS-to-ESM format switch. No speculative compatibility changes were added.

Formatting, lint, type-checking, binary compilation, and native startup checks pass. #6712 is now based on this branch, with the build conflicts resolved while preserving these options.

@jgoux
jgoux merged commit 31820ab into perf/stack-managed-snapshots Sep 23, 2026
51 checks passed
@jgoux
jgoux deleted the perf/cli-compile-bytecode branch September 23, 2026 08:11
jgoux added a commit that referenced this pull request Sep 23, 2026
Local and database-URL TypeScript generation now emits the generator’s
unformatted output, removing the oxfmt implementation and native addon
from the compiled CLI. The CLI explains on stderr that users can format
the output after saving it. TypeScript returned by the Management API
and Go, Python, and Swift generation are unchanged.

Builds replace the unused typegen formatter import with a stub and
retain the shared minification, ESM, and bytecode settings from #6708.

---------

Co-authored-by: Julien Goux <hi@jgoux.dev>
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.

2 participants