-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] npm exec --workspaces very slow #5509
Comments
That's an intriguing one, nice find @gavinsharp thanks for submitting it! The linked PRs and codepaths doesn't really look like they are the actual source of the problem but rather pointing that the problem manifests once It wouldn't surprise me if the problem is actually in |
I believe I've identified the culprit. I was investigating why, in our monorepo that contains 35 workspaces, I encounter those awful performances: $ time npm exec rimraf dist
real 0m3.991s
user 0m6.526s
sys 0m2.711s
$ time ./node_modules/.bin/rimraf dist
real 0m0.101s
user 0m0.090s
sys 0m0.019s dist/ directory was empty in both cases, and according to these numbers, Running npm exec in verbose mode yields that:
Let me draw your attention to:
With a debugger, I identified this line: https://github.com/npm/map-workspaces/blob/e54d4254ab8d712e03cd3fbd4a46fd1bc98c8572/lib/index.js#L101, which basically list every directory matching With a quick and dirty instrumentation, I get:
For a total of approx 3s. Running I've tried node-glob alone, outside of npm, and the performances are indeed awful. I'll have a look. Nonetheless, I'm wondering why we need to glob all those directories, multiple times (and with the same parameters). |
I've just noticed that the Switching to an explicit list of directories removes a lot of overhead: $ time npm exec rimraf dist
real 0m0.628s
user 0m0.676s
sys 0m0.174s It seems there's still a 500ms overhead due to npm, but from what I can see, that's just the overhead of loading every npm dependencies. Running |
I wonder if anything from this blog post is related https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-4/ |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
We have a monorepo using npm workspaces, containing ~70 workspaces/packages.
We noticed that running
npm exec --workspaces
(for example,npm exec --workspaces --call 'pwd'
) at the top-level of this monorepo was incredibly slow - the npm process would be pegged at 100% CPU and it would take multiple seconds to print the directory path for each workspace.The overall run time of
npm exec --workspaces --call 'pwd'
can take several minutes.I was able to bisect NPM release versions to identify that this command was fast in version 8.7.0, but slow in version 8.8.0, so it appears that #4643 introduced the slowness (cc @ruyadorno). Indeed if I locally revert the change from that PR (modified revert due to subsequent changes from #5250), the performance issue disappears:
Expected Behavior
npm exec --workspaces --call 'pwd'
should very quickly (<2s) print out all workspace directories.Steps To Reproduce
npm exec --workspaces --call 'pwd'
Environment
The text was updated successfully, but these errors were encountered: