Skip to content

[Performance] Optimize CLI startup and project discovery#7498

Open
gonzaloriestra wants to merge 1 commit intomainfrom
bolt/optimize-startup-and-discovery-15894214764489785463
Open

[Performance] Optimize CLI startup and project discovery#7498
gonzaloriestra wants to merge 1 commit intomainfrom
bolt/optimize-startup-and-discovery-15894214764489785463

Conversation

@gonzaloriestra
Copy link
Copy Markdown
Contributor

@gonzaloriestra gonzaloriestra commented May 8, 2026

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.

  1. Lazy-load fast-glob in globSync:
    The fs.ts module in cli-kit is a core utility imported by almost every command. By removing the top-level fast-glob import and deferring it until globSync is actually called (using createRequire), we reduce the module's initial execution cost. (Note: the async glob function already uses dynamic import()).

  2. Fast-path for getProjectDir:
    The getProjectDir function is called during currentProcessIsGlobal to check if the CLI is running within a project. It previously used globSync for every directory it traversed. By checking for the most common config files (shopify.app.toml, hydrogen.config.js, hydrogen.config.ts) with fileExistsSync first, we bypass the expensive globbing logic and the loading of the globbing library in the vast majority of cases.

Expected Impact:

  • Reduced CLI startup time.
  • Faster project root discovery.
  • Reduced memory footprint during initial startup.

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

- 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).
@google-labs-jules
Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label May 8, 2026
@gonzaloriestra
Copy link
Copy Markdown
Contributor Author

/snapit

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

🫰✨ 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-20260508081640

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

@gonzaloriestra gonzaloriestra added the Jules Created by Jules label May 8, 2026
@gonzaloriestra gonzaloriestra marked this pull request as ready for review May 8, 2026 08:30
@gonzaloriestra gonzaloriestra requested a review from a team as a code owner May 8, 2026 08:30
Copy link
Copy Markdown
Contributor

@byrichardpowell byrichardpowell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get a performance benchmark or bundle diff before merging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Jules Created by Jules no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants