[Performance] Optimize CLI startup and project discovery#7498
[Performance] Optimize CLI startup and project discovery#7498gonzaloriestra wants to merge 1 commit intomainfrom
Conversation
- Defer `fast-glob` loading in `fs.ts` using `createRequire`. - Implement fast-path for project discovery in `is-global.ts` using `fileExistsSync`. These changes reduce initial execution overhead and avoid expensive directory scans during a common hot path (identifying if the CLI is running in a global context).
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
/snapit |
|
🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260508081640Caution After installing, validate the version by running |
byrichardpowell
left a comment
There was a problem hiding this comment.
Could we get a performance benchmark or bundle diff before merging?
Performance Optimization: CLI Startup and Project Discovery
This PR implements two small but effective performance improvements targeting the CLI's initial startup and project root discovery.
Lazy-load
fast-globinglobSync:The
fs.tsmodule incli-kitis a core utility imported by almost every command. By removing the top-levelfast-globimport and deferring it untilglobSyncis actually called (usingcreateRequire), we reduce the module's initial execution cost. (Note: the asyncglobfunction already uses dynamicimport()).Fast-path for
getProjectDir:The
getProjectDirfunction is called duringcurrentProcessIsGlobalto check if the CLI is running within a project. It previously usedglobSyncfor every directory it traversed. By checking for the most common config files (shopify.app.toml,hydrogen.config.js,hydrogen.config.ts) withfileExistsSyncfirst, we bypass the expensive globbing logic and the loading of the globbing library in the vast majority of cases.Expected Impact:
How to test your changes?
Run any Shopify CLI command (e.g.,
shopify version) to verify it still functions correctly.PR created automatically by Jules for task 15894214764489785463 started by @gonzaloriestra