perf: skip the MCP server, prompt library, and Playwright until a command needs them
e2e --version,--help,run, andlistno longer load the MCP server,@clack/prompts, orzodat startup.mcp,init,login,logout,models,explore,upgrade,doctor, and--watchimport their module when they run.--versionreads 260 files, 2.2 MB, instead of 438 files, 4.6 MB.liston a web project reads 336 files, 3.1 MB, instead of 517 files, 11.9 MB.- The bounds and choice lists a flag needs moved into modules that import nothing heavy, so defining a flag loads nothing. These are
SESSION_BOUNDS,STEP_BOUNDS,TIMEOUT_BOUNDS,PROVIDER_IDS, and theupgradetarget parser. @e2e-dev/webimportsplaywright-coreat the first browser lookup, launch, or attach.e2e listnever loads it, and neither does the main process of a run on a CDP-attached or provider-hosted browser.browserCheckandensureBrowsersInstalledare async now.BrowserConnection.acquiresetspendingbefore it awaits, because the first call now loads Playwright. Adisposethat arrived during that load would miss the browser the launch then produced, and two callers could each launch one.e2e/runnerloads the explorer whenexploreis called.@e2e-dev/acploads the ACP SDK and the MCP server at its first session, and@e2e-dev/limrunloads@limrun/apiat its first lease. A missing@limrun/apinow fails at that lease instead of at config import.- A
STARTUPtable inpackage-imports.test.tsfails with the import chain when the CLI, runner, worker, acp, limrun, or web entry reaches one of these packages through static imports again. The scan also countsimport { type X } from 'x'as a runtime import, becauseverbatimModuleSyntaxleavesimport {} from 'x'in the output.
Measured
main at 76a5280b against this change, on one Apple M1 Max with Node 26.12.1, measured before the last rebase onto 4dce5a76, a tap-position fix that does not touch loading. The runs alternate between the two builds in random order. Each row is the median of the paired runs with the 95% bootstrap interval of the paired change, computed by scripts/bench-ab/stats.ts. All 14 rows are faster against a threshold of 3% and 10 ms.
| Scenario | main | this PR | change (95% CI) | pairs |
|---|---|---|---|---|
e2e --version | 272 ms | 198 ms | -27.4% (-27.8% to -27.0%) | 30 |
e2e --help | 272 ms | 198 ms | -27.2% (-27.6% to -26.7%) | 30 |
e2e list, web project, 4 tests | 452 ms | 238 ms | -47.4% (-47.6% to -47.0%) | 30 |
e2e list, testbed, 51 files | 567 ms | 379 ms | -33.3% (-33.9% to -32.9%) | 20 |
e2e init --yes, new directory | 295 ms | 245 ms | -16.7% (-17.3% to -16.1%) | 15 |
e2e doctor --target web | 450 ms | 415 ms | -8.1% (-8.4% to -7.5%) | 20 |
e2e mcp, until tools/list answers | 386 ms | 363 ms | -5.8% (-6.2% to -4.7%) | 20 |
e2e run, local browser, 1 worker, 4 tests | 1.75 s | 1.69 s | -3.7% (-4.1% to -3.3%) | 20 |
e2e run, CDP attach, 1 worker, 4 tests | 1.83 s | 1.63 s | -10.8% (-11.4% to -9.9%) | 20 |
e2e run, CDP attach, 3 workers, 4 tests | 1.56 s | 1.36 s | -13.2% (-13.4% to -12.8%) | 20 |
import @e2e-dev/web | 316 ms | 166 ms | -47.5% (-47.8% to -47.1%) | 20 |
import @e2e-dev/limrun | 203 ms | 141 ms | -30.6% (-31.4% to -30.2%) | 20 |
import @e2e-dev/acp | 223 ms | 194 ms | -13.3% (-13.7% to -12.9%) | 20 |
import e2e/runner | 207 ms | 183 ms | -12.2% (-12.5% to -11.6%) | 20 |
The imports include about 100 ms of Node starting. Peak memory of the largest process drops from 104 MB to 85 MB for --version, from 181 MB to 91 MB for list on the web project, and from 228 MB to 142 MB for list on the testbed. run stays at about 200 MB.
A local launch still loads Playwright in the main process, in prepare, and in every worker, so run saves only the CLI's startup, 40 to 70 ms. A run whose browser is attached over CDP skips Playwright in the main process too.
pnpm bench:ab --suite testbed --threshold 3 --min-pairs 30 --max-pairs 30 -- tests/forms.e2e.ts ran every test through the same steps with the same outcome on both builds, and every counter matched.
| Metric | main | this PR | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 3.21 s | 3.17 s | -1.3% (-1.6% to -1.0%) | same |
| suite (sum of attempts) | 1.97 s | 2.11 s | +7.2% (+6.7% to +7.6%) | slower |
The slower row comes from one test, the first one a worker runs. fills, clears, and submits a profile takes 1.51 s on main and 1.66 s here. A worker now loads Playwright for its first browser inside that attempt. It used to load it with the config, before any attempt started. When each worker loads Playwright before it starts, using NODE_OPTIONS=--import, the first attempt is 14 ms over main and the process takes as long as before, 3150 ms with the preload and 3155 ms without, over 8 runs each. The work moved and did not grow. The changeset says so.
Verified
Ran it locally: yes
- Built CLI against
mainon 27 commands, covering--helpof every changed command, flag-bound errors,login,logout,models,upgradeargument errors,explore,doctor, andlist. Stdout, stderr, and exit code are identical. run --watchin a pty shows the same screen asmain.init --yeswrites the same 16 files and links and prints the same text.upgrade --dry-runin the testbed prints the same line and exits 0.e2e mcpanswersinitializeandtools/listwith the same 5 tools.- The emitted
.d.tsfiles ofe2e,@e2e-dev/web,@e2e-dev/acp, and@e2e-dev/limrunare unchanged at every entry point. The files that differ are internal modules. - The new tests fail on the old code. With
pendingset after the registration,disposesees 0closecalls on the browser and two callers launch twice. Without itsawait,browserCheckreports an uninstalled browser as installed. - Not run: browsers hosted by Kernel, smol, lightpanda, BrowserStack, or TestMu, which need credentials or binaries that are not available here. The CDP rows stand in for them, since
preparereturns early for a lease the same way it does forconnect.
š¤ Generated with Claude Code