-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Feature] Improve performance of yarn run
#2575
Comments
Timing are always funny 😄 we got a very similar two days ago, and some improvements have landed: #2560 However my fix should mostly have an effect on the PnP linker, so perhaps there's something similar that needs to be done for the nm one? We should get a CPU stack sample to have a better idea. |
Hah, perfect 😀 No real difference running from sources, tho. $ yarn set version from sources && yarn
$ yarn --version
2.4.0-git.20210306.hash-fea486ce
$ hyperfine -w 5 'yarn lint-staged' 'npx lint-staged' 'npm exec lint-staged'
Benchmark #1: yarn lint-staged
Time (mean ± σ): 1.412 s ± 0.063 s [User: 1.705 s, System: 0.200 s]
Range (min … max): 1.353 s … 1.526 s 10 runs
Benchmark #2: npx lint-staged
Time (mean ± σ): 627.2 ms ± 122.9 ms [User: 520.5 ms, System: 133.5 ms]
Range (min … max): 561.3 ms … 969.8 ms 10 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark #3: npm exec lint-staged
Time (mean ± σ): 549.7 ms ± 29.4 ms [User: 476.2 ms, System: 120.0 ms]
Range (min … max): 518.9 ms … 613.5 ms 10 runs
Summary
'npm exec lint-staged' ran
1.14 ± 0.23 times faster than 'npx lint-staged'
2.57 ± 0.18 times faster than 'yarn lint-staged' |
Fresh run after the 2 PRs (same sequence of commands as above)
so it has definitely improved! 👏 1.9x of |
Somewhat related discussion: #2117 A big part of the startup overhead is node having to parse the entire yarn bundle and launch the WebAssembly libzip implementation. If nodejs/node#36812 would ever be implemented in node, performance in such cases should hugely improve. Yarn could then be distributed as separate |
yarn run
We hit this too, unfortunately with ~ 25 packages, the overhead of running We worked around this by switching runs to a different tool like — https://www.npmjs.com/package/workspaces-run |
We run node_modules/.bin directly to workaround this. |
This is so bad for me that if I'm running a large amount of tests with yarn run it will crash most of the apps running on my computer. |
This comment was marked as duplicate.
This comment was marked as duplicate.
@sotnikov-link I marked your comment as duplicate because it was taking a bunch of vertical space for things we already know. Generally, comparing shell performances w/ Still, we really want to improve the |
@arcanis I wanted to show people different between Now, I tried turbo and it works for me faster than turbo.json {
"$schema": "https://turborepo.org/schema.json",
"pipeline": {
"clean": {
"inputs": ["dist/**", ".next/**", "storybook-static/**"]
},
"prepare": {
"dependsOn": ["^prepare"],
"inputs": ["**/*.tsx"],
"outputs": ["dist/**", ".next/**", "storybook-static/**"]
},
"start": {
"dependsOn": ["prepare"]
}
}
}
|
A use case I've run into this issue pretty substantially is scripts running nested scripts within a large monorepo. The root package.json has a bunch of scripts that delegate to various workspaces or other helper scripts, sometimes leading to 3-4 Would one partial possible solution/workaround to scripts running scripts be to reuse the existing yarn process if it can tell it's just running another script? Like "if script starts with yarn, and the next argument matches a script in this file, run that script". It doesn't solve all of these cases but does resolve some. I'm not familiar enough with yarn to know if this is possible, but it'd potentially cut down on some overhead. From a short test, even a single nested call is leading to an
Edit: seems there's actually an issue tracking this (#3732) |
I optimized If someone wants to help improve that further! |
sometimes deplay is really big:
3 secods + 0.5s |
Describe the user story
Running
yarn jest
has a significant performance overhead in Yarn v2 vs Yarn v1 (ornpx
). The following commands are run in a repo installed using yarn v2, with the node-linker. Yarn v1 is run from the brew installed version, no local version in the repo. Note that all runs are without runningyarn
ornpm
in between - they all run against a repo installed using Yarn v2Then for yarn v1 (by doing
rm .yarnrc*
)While it doesn't matter too much in the case of Jest (although perceived startup performance is noticeably worse when running tests since there's no output), it's quite annoying when running tools as git hooks.
And with yarn v1
When rebasing lots of commits, that almost 1.5s of overhead (or 1s in the case of yarn v1) adds a lot of time spent. It's gotten to the point where I pass
-n
if I'm making lots of commits (or rebase) as it takes way too long to run.For reference, I've been running these benchmarking runs in https://github.com/jest-community/eslint-plugin-jest
Describe the solution you'd like
I'd like it to be faster 😀
I expect some overhead of yarn v2 simply due to the fact it needs to first spawn yarn v1, find the config, then load yarn v2. But almost 3x time spent in execution is way more than I expected.
I assume you've already tried to optimize the overhead added by yarn when running scripts, but maybe some checks for "PnP compliance" or whether the lockfile is in sync with all package.jsons can be dropped for the node linker? Possibly via some flag which we can then use when we want, although a flag saying "just do it, don't check" might not be feasible? And a flag saying "give me perf" is probably weird and few people will know about it
Describe the drawbacks of your solution
I don't think there's any drawbacks to improving performance, but I don't know enough about Yarn's innards to comment on technical drawbacks of whatever optimization is applied.
Describe alternatives you've considered
Stop using
yarn
as binary runner and usenpx
ornpm exec
instead, at least in commit hooks and such.The text was updated successfully, but these errors were encountered: