cli: [Bug]: bad startup performance

Please confirm that you have:

  • Searched existing issues to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
  • Reproduced the issue in the latest CLI version.

In which of these areas are you experiencing a problem?

Theme

Expected behavior

Running shopify theme dev --store shop.myshopify.com starts executing immediately.

Actual behavior

Running any command (version as well) takes 5+ seconds to run. For a modern application we are running hundreds of times a day thats not really great.

Verbose output

❯ get-date; shopify theme dev --store shop.myshopify.com --verbose 

Freitag, 2. Juni 2023 15:23:37
2023-06-02T13:23:47.635Z: Running command theme dev

Reproduction steps

  1. run any command

Operating System

Windows 11 22H2 (22621.1702)

Shopify CLI version (check your project’s package.json if you’re not sure)

3.46.2

Shell

powershell with starship

Node version (run node -v if you’re not sure)

v16.14.2

What language and version are you using in your application?

ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt], pnpm 8.6.0

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 15 (7 by maintainers)

Most upvoted comments

This all sound fairly lame. I think it is obvious that V3 CLI runs very slowly and to say it is a “Windows” thing is not really a valid response. I run node under Windows and Linux as well as in WSL and all other packages do not have extreme differences in performance. Has any analysis been done as to why exactly it runs slow, which dependencies, alternatives etc? Just letting the issue close appears the lazy option.

From here it looks like Microsoft is pretty open about being very slow for Node applications. So unless we’d choose to rewrite the CLI in another language (unlikely at the moment), this isn’t something we can fix easily.

However, as mentioned above, WSL is a very good option. Additionally, Windows Insider builds have a Dev Drive feature where you can move your npm cache for significantly better performance.

@muchisx it looks like some of what you’re experiencing is slowness on refreshing your login. Recall that on CLI2 you’d run a command, get told to log in again, then log in, then run the command and succeed? On CLI3 we take care of this within the command, including refreshing your authentication. We could probably give better UI feedback about what’s happening (e.g. a taskbar saying we’re refreshing your authentication) but it’s impossible to circumvent the need to be certain we have valid authentication before proceeding. That’s also why the second run of the command is significantly faster.

I ran shopify version with process monitor running to take a deeper look. After running the shell shim, node instantly starts up and begins to load a massive amount of dependencies: imageimage

until it finally loads the shopify files, runs, and returns instantly.

image

Adding most of the files node accesses to the allowlist of defender improved performance by ~30%, but it was not the improvement I hoped for.

I would love to try out snapshotting for node, like in https://blog.logrocket.com/snapshot-flags-node-js-v18-8/

Maybe we could create the snapshot on first run and store it.