Repository navigation
perf(cli): defer Playwright and isomorphic-git until a command needs them - #1439
Conversation
The capture-browser-scenario command imported its Playwright-backed provider at module scope, so every CLI invocation loaded playwright-core (about 95 ms of startup) even when no browser was involved. Import the composition when the command runs, as capture-electron-scenario already does. Light commands start about 100 ms faster. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
… state import-reference-source is the only consumer, but the static import made every CLI and MCP process load isomorphic-git and its Buffer polyfills (about 17 ms of startup). Extend the startup import test to cover it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Independent review of
The actual stdio probe still resolves Playwright during MCP startup; it skips isomorphic-git. I corrected the description to keep the Playwright savings scoped to CLI registration. Final-head CI is 19/19 successful. No source changes were needed in review. Thanks for isolating these optional startup dependencies without changing the default response contract. |
|
TL;DR: This merged while I was testing. So this is a post-merge check on Linux. Every command I tried got faster. Startup dropped about 20% on Node 22, 24 and 26. Memory dropped about 35 MiB. Playwright and Git code now load only on demand. Browser capture still works. This is one box, so take the numbers as rough. Speed and memory (
|
| Node | startup, median of 12 | peak RSS, median of 5 |
|---|---|---|
| 22.23.1 | 1508 → 1181 ms (−22%) | 272 → 236 MiB |
| 24.18.0 | 1269 → 1005 ms (−21%) | 338 → 305 MiB |
| 26.11.1 | 1106 → 879 ms (−21%) | 301 → 265 MiB |
All eight timed commands got 15% to 22% faster. Load sat near 3, with another job running. This box is slower than the PR's Mac. The share saved is close.
What loads (rea --help, same on all three Nodes)
| base | head | |
|---|---|---|
| modules resolved | 1642 | 1268 |
| playwright-core files | 279 | 0 |
| isomorphic-git files | 2 | 0 |
Head still loads each one when a command needs it.
Nothing broke
| Check | 22 | 24 | 26 |
|---|---|---|---|
verify:browser, head, Chromium 154 |
- | pass | - |
Real capture-browser-scenario, head |
- | pass | - |
import-reference-source, six .git layouts |
same | - | - |
| PR body's nine test files, head | - | pass | - |
| New test plus touched tests, head | pass | pass | pass |
| New test on base | fails | fails | fails |
The base failure is the point. It sees both packages at startup.
Not run
list-architectures XLDneeds macOS and XLD. I timed it here only as a fast error.demangle-swift xalso errors here, on both sides. It still measures startup.- I did not time
rea mcpstartup. - I ran
verify:browseron head and Node 24 only. - I did not run the full test suite.
Thanks, kaoru0822-kitauji, for a small change with a clear test.
Check details
verify:browserreports"verified": true. It drivescapture-browser-scenariothrough the CLI.- The hand-run capture finished all steps on base and head. Head loaded 279 Playwright files for it.
- The six
.gitlayouts gave the same result on base and head. They cover a worktree pointer, a detached HEAD, an empty folder and a bad pointer. - The nine files gave 161 passed and 2 skipped. The skips are Windows only.
- On Node 22 and 26 I ran four files. That was 9 passed and 2 skipped.
- On base the new test fails on one case. It expected an empty set. It got
isomorphic-gitandplaywright-core. - With a real
.git, head loads 79 more modules. So the Git code is deferred, not dropped.
All startup medians (ms, min to max in brackets)
Load average read 2.5 to 3.7 at the start and end of each batch. Another job was running on the box.
| Node | command | base | head | change |
|---|---|---|---|---|
| 22 | --version |
1508 (1474–1633) | 1181 (1147–1217) | −21.6% |
| 22 | demangle-swift x |
1508 (1452–1591) | 1174 (1127–1268) | −22.2% |
| 22 | list-architectures XLD |
1520 (1466–1666) | 1227 (1155–1281) | −19.3% |
| 22 | --help |
1484 (1434–1522) | 1201 (1129–1296) | −19.1% |
| 22 | analyze-javascript-application |
1547 (1498–1636) | 1227 (1197–1306) | −20.7% |
| 22 | inspect-artifact |
1489 (1463–1556) | 1195 (1164–1288) | −19.7% |
| 22 | import-reference-source (git) |
1493 (1437–1538) | 1213 (1189–1317) | −18.8% |
| 22 | import-reference-source (no git) |
1479 (1434–1690) | 1193 (1126–1549) | −19.3% |
| 24 | --version |
1269 (1193–1408) | 1005 (960–1060) | −20.8% |
| 24 | demangle-swift x |
1216 (1140–1346) | 1004 (942–1043) | −17.4% |
| 24 | list-architectures XLD |
1314 (1256–1355) | 1069 (1003–1101) | −18.6% |
| 24 | --help |
1224 (1182–1283) | 977 (943–1035) | −20.2% |
| 24 | analyze-javascript-application |
1251 (1231–1333) | 1040 (1002–1085) | −16.9% |
| 24 | inspect-artifact |
1251 (1195–1349) | 1029 (973–1099) | −17.8% |
| 24 | import-reference-source (git) |
1208 (1180–1288) | 1022 (979–1048) | −15.4% |
| 24 | import-reference-source (no git) |
1229 (1183–1337) | 1017 (957–1071) | −17.3% |
| 26 | --version |
1106 (1072–1124) | 879 (847–916) | −20.5% |
| 26 | demangle-swift x |
1111 (1076–1128) | 874 (857–894) | −21.3% |
| 26 | list-architectures XLD |
1105 (1063–1221) | 875 (844–955) | −20.8% |
| 26 | --help |
1061 (1046–1188) | 864 (829–953) | −18.6% |
| 26 | analyze-javascript-application |
1135 (1081–1234) | 898 (870–960) | −20.9% |
| 26 | inspect-artifact |
1155 (1095–1198) | 910 (874–1005) | −21.2% |
| 26 | import-reference-source (git) |
1107 (1071–1128) | 896 (879–955) | −19.1% |
| 26 | import-reference-source (no git) |
1068 (1050–1144) | 852 (840–876) | −20.2% |
All peak memory medians (MiB, min to max in brackets)
| Node | command | base | head | change |
|---|---|---|---|---|
| 22 | --version |
272.4 (267.4–273.4) | 235.5 (232.8–239.8) | −36.9 |
| 22 | --help |
270.4 (267.2–271.7) | 234.7 (232.2–237.2) | −35.7 |
| 22 | analyze-javascript-application |
278.1 (275.4–279.5) | 246.5 (242.9–250.6) | −31.6 |
| 22 | import-reference-source (git) |
271.6 (271.0–274.2) | 243.2 (240.0–244.7) | −28.4 |
| 24 | --version |
337.9 (335.9–338.3) | 304.5 (304.1–306.6) | −33.4 |
| 24 | --help |
337.5 (336.2–338.8) | 305.0 (304.7–305.3) | −32.4 |
| 24 | analyze-javascript-application |
361.3 (342.0–362.8) | 321.0 (317.4–321.3) | −40.3 |
| 24 | import-reference-source (git) |
340.7 (336.0–341.0) | 309.1 (308.3–315.0) | −31.6 |
| 26 | --version |
301.1 (300.0–301.6) | 264.5 (263.8–264.6) | −36.6 |
| 26 | --help |
300.2 (299.5–301.1) | 262.9 (260.7–263.8) | −37.4 |
| 26 | analyze-javascript-application |
302.4 (301.0–303.7) | 274.6 (268.2–276.2) | −27.9 |
| 26 | import-reference-source (git) |
301.4 (299.2–302.3) | 263.8 (263.4–266.2) | −37.6 |
Commands
Timing: two warm-up pairs, then 12 pairs. Base and head swap order each pair. Exit codes matched on every run.
nice -n 10 taskset -c 2,3 node scripts/rea.mjs <args> >/dev/null 2>&1Memory: five pairs, not pinned.
/usr/bin/time -v node scripts/rea.mjs <args> # "Maximum resident set size"Module log: a module.registerHooks resolve hook that writes each resolved URL.
node --import=./hook.mjs scripts/rea.mjs --helpTargets: a two-file JS app, one small JS file, and folders with hand-made .git layouts.
Browser check:
dbus-run-session -- env -i PATH=... HOME=<scratch> TMPDIR=/tmp/<short> \
REA_BROWSER_EXECUTABLE=/usr/bin/chromium-browser npm run verify:browserTests:
npm run test:focused -- <the nine files from the PR body>
node scripts/run-development-tests.mjs focused tests/boundary/cli/cliStartupImports.test.ts ...Test setup
- Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
- CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
- RAM: 32 GB DDR4-3600
- Node: 22.23.1, 24.18.0, 26.11.1
- Head / base:
d992433b/0b9815b6(merged aseeb83f65) - Other: Chromium 154.0.8037.57 (BSD-3-Clause), Playwright 1.58.2 (Apache-2.0)
🤖 Generated with Claude Code (Opus 5.5) 🦊
Summary
capture-browser-scenarioimported its Playwright-backed provider (composition/browserScenario.js→PlaywrightScenarioBrowser→playwright-core) at module scope. Because the CLI registers every command at startup, everyreainvocation loadedplaywright-core, about 95 ms in a CPU profile, even for commands that never use a browser. The command now imports the composition when it runs.capture-electron-scenarioalready does this (src/cli/electronCommands.ts). This Playwright improvement applies to CLI command registration. Actual stdio MCP startup still resolves Playwright;loadOptionalObservationProvidersinvokes its dynamic provider factories during startup.Agents that drive REA through the CLI pay this startup cost on every call. Related to the responsiveness work in #1065.
A second commit does the same for
isomorphic-git. Onlyimport-reference-sourceuses it, throughReferenceSourceVcsAdapter, but the static import also loaded it and its Buffer polyfills (sha.js,to-buffer,typed-array-buffer, …) in every CLI and MCP process.Measurements (macOS arm64, Node 26.5, median of 12 runs after 2 warmups, both commits vs main)
rea --versionrea demangle-swift xrea list-architectures XLDPlaywright alone accounted for about 95 ms and isomorphic-git for about 17 ms.
Change
src/cliBrowserScenarioCommands.ts: dynamicimport("./composition/browserScenario.js")after input validation, in place of the static import.src/application/ReferenceSourceVcsAdapter.ts:isomorphic-gitis imported insideresolveSourceHead, which runs only when a.gitentry exists. Import failures fall into the existingunknownVCS result, the same as unresolvable refs.tests/boundary/cli/cliStartupImports.test.ts: runs the built CLI with amodule.registerHooksresolve hook that reports resolvedplaywright-coreandisomorphic-gitmodules.rea --helpresolves neither. This fails on main and passes here..git).No contract, output, or error-shape change. Input validation errors are returned before the import, as before.
Verification
npm run test:focused --tests/boundary/cli/cliStartupImports.test.ts,browserCli.test.ts,scenarioCliInputDiagnostics.test.ts,cliToolCoverage.test.ts,jsonInputStatus.test.ts,tests/evaluation/moduleBoundaries.test.ts,tests/boundary/filesystem/referenceSourceVcs.test.ts,referenceSourceImportStatus.test.ts,referenceSourceUtf8.test.ts: all pass.rea capture-browser-scenariowith headless Brave against a local page returned capture Evidence through the lazily loaded provider.npm run typecheck, oxlint and oxfmt; the pre-pushcheck:fastpassed.No real Hopper/Ghidra verification (not affected).
🤖 Generated with Claude Code