berry icon indicating copy to clipboard operation
berry copied to clipboard

perf(cli): use `Module.runMain` instead of `child_process`

Open paul-soporan opened this issue 2 years ago • 2 comments

What's the problem this PR addresses?

Depends on https://github.com/yarnpkg/berry/pull/5595.

When yarnPath points to a different binary from the current one, Yarn forwards the command to the specified binary using child_process.execFileSync, which adds unnecessary overhead.

How did you fix it?

Made it use Module.runMain instead, the same trick we use in corepack starting from https://github.com/nodejs/corepack/pull/97.

This speeds up every command when using Yarn from sources (or in other cases where corepack uses modern, and corepack and yarnPath point to different binaries).

yarn -v in such a situation:

  • Before: 0.263s
  • After: 0.229s
  • Improvement: 13%

Checklist

  • [X] I have set the packages that need to be released for my changes to be effective.
  • [X] I will check that all automated PR checks pass before the PR gets reviewed.

paul-soporan avatar Jul 21 '23 01:07 paul-soporan

I haven't tested it but this might fix https://github.com/yarnpkg/berry/issues/3996.

merceyz avatar Jul 24 '23 16:07 merceyz

:thinking: Most likely, indeed.

@arcanis Can you please take a look at the v1 PR (https://github.com/yarnpkg/yarn/pull/8793) so we can fully close that issue?

paul-soporan avatar Jul 25 '23 02:07 paul-soporan