Repository navigation
Studio CLI: Import each date-fns function from its own path - #5313
Merged
Merged
Conversation
The date-fns root loads all of its functions, about 300 modules, on every studio command. Each function has its own path.
Collaborator
📊 Performance Test ResultsComparing 42d8fc2 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) |
This was referenced Oct 23, 2026
youknowriad
reviewed
Oct 23, 2026
| import { isSameDay, isSameMonth, isSameWeek } from 'date-fns'; | ||
| import { isSameDay } from 'date-fns/isSameDay'; | ||
| import { isSameMonth } from 'date-fns/isSameMonth'; | ||
| import { isSameWeek } from 'date-fns/isSameWeek'; |
Contributor
There was a problem hiding this comment.
Maybe this PR needs a small note in agents.md to prevent it from happening again.
1 task done
chubes4
added a commit
that referenced
this pull request
Oct 27, 2026
## Related issues - Follows #5235, #5313 and #5316, which kept the MCP server, the `date-fns` root and `@inquirer/prompts` off 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.ts` statically imported every top-level command module, and each module held the command's whole implementation. So every `studio` invocation 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 for `studio --version`. Each top-level command now has a `.command` module that defines the command (name, description, options) and loads the implementation with `await import()` in its handler, the pattern `wp` and `_events` already use. The implementation modules keep their paths and their `runCommand` exports, so their other callers are unchanged; each one's former handler body is now its exported `commandHandler`. - `studio list`, `start`, `stop`, `create` and `wp` load 520 dependency files at startup instead of 1,375. - Help output, unknown-command errors and option validation are byte-identical to trunk. - A `CommandArgs< typeof builder >` type keeps each handler typed from its command's options. Local timings on macOS (median of 8 alternating runs, Node 24): | Command | trunk | this PR | | --- | --- | --- | | `studio --version` | 0.40 s | 0.21 s | | `studio list` | 0.39 s | 0.23 s | | `studio status` | 0.42 s | 0.24 s | | `studio wp option get blogname` | 0.67 s | 0.48 s | | `studio stop` / `start` (already in that state) | 0.44 s | 0.26 s | 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 what `index.ts` imports statically must not load any command implementation. Making a `.command` module import its implementation statically fails it. - Build the CLI and compare `studio --help`, `studio create --help` and `studio foo` with trunk's output. - Time `studio list` or `studio wp option get blogname` against trunk. ## 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
studiocommand from loading the agent runtime. The Studio app runs the CLI for nearly everything (site list, start, stop, events), so CLI startup time adds to each of those.How AI was used in this PR
Claude (via the Pi coding agent in a Roadie session) profiled
studiostartup in the packaged app, found the cost, wrote the change and the test, and took the timings below. I reviewed the diff and the numbers.Proposed Changes
The CLI keeps its npm dependencies external, so an import of the
date-fnsroot loads every date-fns function: about 300 modules, for the 8 functions Studio uses. With the packaged app's Node andnode_modules,import( 'date-fns' )alone takes about 0.9 s;import( 'date-fns/isSameDay' )takes about 15 ms. Everystudiocommand paid this, becauselib/snapshots.tsandlib/site-runtime-stats.tsare on the startup path.date-fns/format, …), in the CLI and in the two@studio/commonfiles the CLI uses.DurationUnitstays a type-only import from the root, which is erased at build time.date-fnsroot. It fails on trunk.Testing Instructions
npx vitest run apps/cli/tests/startup-imports.test.tspasses; on trunk it fails.packages/commontests (87 files, 862 tests) pass.resources/bin/nodeandresources/cli/node_moduleswith each build'sdist/cli, runs interleaved:studio site list --help, 12 runsstudio --version, 7 runsstudio --versionsiteCreationandsiteStartup.Pre-merge Checklist