perf: smaller minified output and a lighter eager CLI startup path#1065
Conversation
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).
fc16f45 to
91dad15
Compare
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
|
Rebased onto current 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 Validation I ran locally on the rebased head:
Current GitHub CI is green except one |
|
Final CI refresh: the last Smoke Tests job is now green and GitHub reports the PR as clean. Added |
|
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 }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:parser/args.ts→cli-help.tscli.ts/generic.ts→replay/test/reporting.tstestcommands/screenshot.ts→createAgentDevice(client runtime incl. pixel diffing)diff screenshotThese 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/--versionfast paths inbin.tsare unchanged (medians within noise before/after).Evaluated and intentionally not included
splitChunksminSize tuning for the ~43 sub-3 kB chunks: measured as a byte-identical no-op — those files are dynamic-import boundaries, not split products.cli-help.jsfrom the 191 kB shared schema/runtime chunk (thehelp <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 ifhelplatency ever matters enough.Size report
Testing
pnpm lint,pnpm typecheck,pnpm check:layering,pnpm check:fallow,pnpm check:mcp-metadata,pnpm format:checkall passpnpm test:unit: 3039/3041 pass; the one failing file (daemon-client.test.ts) passes in isolation (known flaky-under-contention pattern)pnpm test:smokepasses against the built CLIhelp snapshot,snapshot --help, unknown-command error path, bare usage output all verified against the built bundle