Skip to content

perf: smaller minified output and a lighter eager CLI startup path#1065

Merged
thymikee merged 2 commits into
mainfrom
claude/blissful-jepsen-cc6ff2
Jul 4, 2026
Merged

perf: smaller minified output and a lighter eager CLI startup path#1065
thymikee merged 2 commits into
mainfrom
claude/blissful-jepsen-cc6ff2

Conversation

@thymikee

@thymikee thymikee commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

Follow-ups from a package-size audit (2.09 MB unpacked / 0.61 MB tarball). The audit found the bundle is already clean — no vendored deps, no cross-chunk duplication, no blobs — so this PR takes the levers that survived measurement:

1. SWC minifier: compress: { passes: 3 }

  • −9.1 kB raw / −6.4 kB tarball, one config line, no runtime cost.

2. Lazy-load help text, replay reporting, and diff runtime on the CLI path

Every CLI invocation (including snapshot) eagerly parsed 599 kB of JS. Three static imports were responsible for code most commands never run:

Edge Weight Only needed for
parser/args.tscli-help.ts 75 kB help + usage-error paths
cli.ts / generic.tsreplay/test/reporting.ts ~17 kB test
commands/screenshot.tscreateAgentDevice (client runtime incl. pixel diffing) 68 kB diff screenshot

These are now dynamic imports at their call sites. Eager closure of cli.js: 599 kB → 431 kB (−28%), ~2.5 ms median module-load win per command invocation. The --help/--version fast paths in bin.ts are unchanged (medians within noise before/after).

Evaluated and intentionally not included

  • splitChunks minSize tuning for the ~43 sub-3 kB chunks: measured as a byte-identical no-op — those files are dynamic-import boundaries, not split products.
  • Decoupling cli-help.js from the 191 kB shared schema/runtime chunk (the help <cmd> path still loads it): help content derives from the live command-schema surface, and the facet files co-locate metadata with runtime, so breaking that edge means either splitting ~60 facet modules or build-time data extraction. Worth its own discussion if help latency ever matters enough.
  • Non-JS payload (apple-runner 384 kB etc.) is required at runtime — audited, nothing excludable.

Size report

Metric Base Current Diff
JS raw 1.5 MB 1.5 MB −9.1 kB
JS gzip 483.4 kB 477.8 kB −5.7 kB
npm tarball 608.4 kB 602.0 kB −6.4 kB

Testing

  • pnpm lint, pnpm typecheck, pnpm check:layering, pnpm check:fallow, pnpm check:mcp-metadata, pnpm format:check all pass
  • pnpm test:unit: 3039/3041 pass; the one failing file (daemon-client.test.ts) passes in isolation (known flaky-under-contention pattern)
  • pnpm test:smoke passes against the built CLI
  • Manual: help snapshot, snapshot --help, unknown-command error path, bare usage output all verified against the built bundle

thymikee added 2 commits July 4, 2026 02:13
Measured -9.7 kB raw / -7.0 kB npm tarball on the emitted JS at no
runtime cost. splitChunks minSize tuning was also evaluated for the
tiny-chunk overhead but measured as a byte-identical no-op (the sub-kB
files are dynamic-import boundaries, not split products), so it is
intentionally not included.
… eager command path

Every CLI invocation eagerly parsed 599 kB of JS. Three static imports
dragged in code that most commands never run:

- cli.js -> cli-help.js (75 kB of help text) via the usage()/
  usageForCommand() builders in parser/args.ts, which are only needed
  on help and usage-error paths. They now lazy-import cli-help.ts.
- cli.ts/generic.ts -> replay/test/reporting.ts (~17 kB), only needed
  by the test command. Now imported at the call sites.
- cli/commands/screenshot.ts -> createAgentDevice (68 kB client-side
  command runtime chunk incl. screenshot pixel diffing), only needed
  by the diff screenshot branch. Now imported inside diffCommand.

Eager closure of cli.js drops 599 kB -> 431 kB (-28%), ~2.5 ms median
module-load per command invocation. --help/--version fast paths in
bin.ts are unchanged. Package size is unchanged by design (the code
moves to lazy chunks; it does not disappear).
@thymikee thymikee force-pushed the claude/blissful-jepsen-cc6ff2 branch from fc16f45 to 91dad15 Compare July 4, 2026 00:13
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 1.5 MB 1.5 MB -9.1 kB
JS gzip 485.2 kB 479.6 kB -5.7 kB
npm tarball 587.3 kB 581.1 kB -6.2 kB
npm unpacked 2.1 MB 2.1 MB -9.1 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.5 ms 27.5 ms +0.0 ms
CLI --help 48.2 ms 48.6 ms +0.5 ms

Top changed chunks:

Chunk Raw diff Gzip diff
dist/src/2426.js +68.3 kB +21.7 kB
dist/src/reporting.js +16.8 kB +6.1 kB
dist/src/cli.js -17.4 kB -6.0 kB
dist/src/9722.js -2.5 kB -1.8 kB
dist/src/session.js -2.0 kB -1.4 kB

@thymikee

thymikee commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Rebased onto current origin/main and pushed the updated branch (91dad155a). The only conflict was in src/utils/__tests__/args.test.ts; I preserved the main-branch tap alias coverage and converted it to the PR's async help API.

Review pass found no actionable blockers. The design looks sound for the stated goal: help text, replay test reporting, and screenshot diff runtime are now loaded only on the paths that need them, while normal command parsing and execution stay synchronous until an actual help/reporting/diff path is selected. I also checked the async propagation: CLI help callers await usage()/usageForCommand(), and the generic test output path is awaited by runGenericClientBackedCommand, so the lazy imports do not create a dropped promise.

Validation I ran locally on the rebased head:

  • pnpm exec vitest run src/utils/__tests__/args.test.ts src/utils/__tests__/perf-args.test.ts
  • pnpm check:quick
  • pnpm build
  • pnpm format
  • pnpm check:tooling
  • built CLI smoke checks: --version, top-level usage, help snapshot, snapshot --help, help test, and unknown-command error handling

Current GitHub CI is green except one Smoke Tests job is still pending from the forced update; I am not adding ready-for-human until that final job completes.

@thymikee

thymikee commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Final CI refresh: the last Smoke Tests job is now green and GitHub reports the PR as clean. Added ready-for-human.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Jul 4, 2026
@thymikee thymikee merged commit e3566b6 into main Jul 4, 2026
21 checks passed
@thymikee thymikee deleted the claude/blissful-jepsen-cc6ff2 branch July 4, 2026 07:04
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-04 07:05 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant