CLI: every studio command spends about a second loading modules before doing any work
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- cli, performance
Research direction
Start with the CLI entry point in apps/cli/index.ts and the locale loader in packages/common/translations/index.ts; compare their current imports with the lazy-command pattern already used by wp. Then trace the remaining imports on the wp path and benchmark studio --version and studio wp option get siteurl against the issue’s baseline. Done means commands still show identical --help output and startup measurements improve without breaking locale use in the CLI, desktop app, or UI.
Written by the indexing model from the issue text.
Description
Every studio invocation, including studio wp and studio --version, spends about a second loading JavaScript before it does any work. This matters most for agents and scripts that call studio wp many times in a row.
Measurements
Production build of trunk on macOS (M-series, Node 24), medians of 5 runs:
| Time | |
|---|---|
node -e 1 |
0.03–0.15 s |
studio --version |
1.16 s |
studio wp option get siteurl |
1.55 s |
| The same WP-CLI command run on Studio's PHP directly | 0.63 s |
So studio wp adds about 0.9 s on top of WP-CLI itself. A CPU profile shows almost no time in Studio code: it's Node resolving, reading and compiling modules.
studio --version loads 3,769 modules (22.8 MB). The biggest contributors:
- Eagerly imported commands.
apps/cli/index.tsstatically importscreate,list,start,stop,delete,status,push,pull,pull-reprint,import,export,ui,uninstallandmcp, so every invocation loads all of their dependencies.mcpalone pulls in the coding-agent runtime (about 1,600 modules).auth,preview,config,blueprintandwpare already lazy. This accumulated rather than being decided: yargs needs a command's definition at the root, and each command module imports its implementation next to its definition. - All translations at once.
packages/common/translations/index.tsimports all 21 locale JSON files, which end up inlined (about 4.5 MB) in a shared chunk that every command loads. Importing that chunk on its own takes about 0.24 s more than an equivalent chunk without it. - Shared libraries on the
wppath: zod, date-fns, yargs, chardet, semver.
Prototype
Registering the 14 eager commands lazily (name and summary at the root, the module loaded in the builder and handler, the same pattern wp already uses) gives:
| Before | After | |
|---|---|---|
Modules loaded by studio wp |
3,769 | 634 |
studio --version |
1.16 s | 0.85 s |
studio wp option get siteurl |
1.55 s | 1.60 s (within noise) |
Every --help output stays identical. studio wp doesn't get faster from this alone, because what remains on its path is mostly the translations chunk and the shared libraries.
Suggested steps
- Register commands lazily.
- Load only the active locale's translations, instead of importing all 21 in
packages/common/translations. This touchesgetLocaleData, which the CLI, the desktop app and the UI all use. - Trace the remaining imports on the
wppath and make the heavy ones dynamic.
Estimated result for studio wp: about 0.9 s, against the 0.63 s floor.
Related: #4343
How AI was used
Claude (via the Pi coding agent in a Roadie session) profiled the CLI, built the lazy-command prototype, and drafted this issue. The numbers come from local runs on a loaded machine, so treat them as approximate.
- Dominant language
- TypeScript
- Stars
- 543
- Forks
- 104
- Avg merge
- 23h 59m
- Merged PRs (30d)
- 276
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Automattic/studio
-
Enhancement
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Automattic/studio#3017 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Automattic/studio#2868 · 2 comments ·
Maintainers usually reply within 1 day
-
Allow the native PHP worker pool size to be configured (hardcoded to 4)Possibly taken @chubes4 claimed this today. Open
Automattic/studio#5238 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
Automattic/studio#5200 · 1 comment ·
Maintainers usually reply within 1 day
-
Theme pattern files are not registered until the pattern cache is clearedPossibly taken @chubes4 claimed this 5 days ago. Open
Automattic/studio#5158 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
All issues in Automattic/studio
Similar issues
-
agent/scanner help wanted hive/claimed-by-scanner kind/bug stage/020-claimed
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
hivecommons/rationguard#315 ·
Maintainers usually reply within 1 day
-
agent-ready area: ui-sdk priority: p3 type: chore
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
schlessera/brain-kit#2534 ·
Maintainers usually reply within 1 day
-
bug lane:gh-5
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
LLM-4-People/bridlewise-testing#122 ·
Maintainers usually reply within 1 day
-
bug priority: P2
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
enhancement priority:low ready-for-dev
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day