Repository navigation
CLI: Load each command's implementation when the command runs - #5495
Merged
Merged
Conversation
Collaborator
📊 Performance Test ResultsComparing 0be02f6 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
Merged
1 task done
chubes4
added a commit
that referenced
this pull request
Oct 27, 2026
…ws CI's time limit (#5499) ## Related issues - Follows #5314, which added this test. ## How AI was used in this PR Claude (via the Pi coding agent in a Roadie session) found the Windows timeouts in CI logs and wrote the change. I reviewed it. ## Proposed Changes The test from #5314 runs eight concurrent installs of a 400-file WordPress copy. It takes about 1 s on macOS but sometimes exceeds Vitest's default 5 s on the Windows Unit Tests agent, which failed Windows Unit Tests on #5494 (build 24210) and #5495 (build 24211) with `Test timed out in 5000ms`. Its trunk runs passed, so it is intermittent. The size adds no detection. Run 5 times each on macOS against #5314's fix and against the code before it: | Size | With the fix | Before the fix | | --- | --- | --- | | 8 installs × 400 files | 5/5 pass | 5/5 fail | | 4 installs × 100 files | 5/5 pass | 5/5 fail | | 2 installs × 50 files | 5/5 pass | 5/5 fail | Before the fix, the failing check is the one this test exists for: `latest` shows `version.php` before all its files are there. This shrinks the test to two installs of 50 files, which keeps the concurrent and interrupted-copy paths at about 1/30 of the file work. ## Testing Instructions - `npx vitest run --project cli apps/cli/lib/dependency-management/tests/setup-server-files.test.ts` passes. With `apps/cli/lib/dependency-management/setup.ts` from before #5314, it fails. - Windows Unit Tests pass in CI. ## Pre-merge Checklist - [x] Have you checked for TypeScript, React or other console errors?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
date-fnsroot and@inquirer/promptsoff CLI startup.How AI was used in this PR
Claude (via the Pi coding agent in a Roadie session) profiled CLI startup, wrote the change and the test, and measured the before/after timings. I reviewed the diff and the measurements.
Proposed Changes
apps/cli/index.tsstatically imported every top-level command module, and each module held the command's whole implementation. So everystudioinvocation loaded the implementation of every command before running one, including the export, import, push and pull code and its archive, upload and certificate libraries: 1,375 dependency files from 109 packages forstudio --version.Each top-level command now has a
.commandmodule that defines the command (name, description, options) and loads the implementation withawait import()in its handler, the patternwpand_eventsalready use. The implementation modules keep their paths and theirrunCommandexports, so their other callers are unchanged; each one's former handler body is now its exportedcommandHandler.studio list,start,stop,createandwpload 520 dependency files at startup instead of 1,375.CommandArgs< typeof builder >type keeps each handler typed from its command's options.Local timings on macOS (median of 8 alternating runs, Node 24):
studio --versionstudio liststudio statusstudio wp option get blognamestudio stop/start(already in that state)The saving is a fixed cost per CLI process, so it applies to every command the desktop app and Studio Code run through the CLI.
Testing Instructions
npx vitest run --project cli apps/cli/tests/startup-imports.test.ts: loading whatindex.tsimports statically must not load any command implementation. Making a.commandmodule import its implementation statically fails it.studio --help,studio create --helpandstudio foowith trunk's output.studio listorstudio wp option get blognameagainst trunk.Pre-merge Checklist