Skip to content
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

perf: load binaries in the same process #97

Merged

Conversation

paul-soporan
Copy link
Contributor

@paul-soporan paul-soporan commented Mar 24, 2022

What's the problem this PR addresses?

While looking into improving Yarn's startup time, we've observed the fact that corepack adds extra overhead by spawning a new process to run the invoked binary.

How did you fix it?

This PR makes corepack load binaries in the same process, removing the spawn indirection and considerably improving the startup time:

package-manager --version Before After
yarn@3.2.0 183.1 ms 159.7 ms
pnpm@6.29.1 92.0 ms 69.8 ms
npm@8.1.0 160.8 ms 131.6 ms

The way it achieves this is by modifying process.{argv,execArgv} and process.mainModule (and the module cache to make sure that require.main === module keeps working) to trick the binary into thinking that it was spawned directly instead of having been loaded into the current process.

It might feel a bit magical at first, but we feel it's worth it.

@paul-soporan paul-soporan changed the title perf: require binaries in the same process perf: load binaries in the same process Mar 25, 2022
@paul-soporan paul-soporan force-pushed the perf/binaries-in-the-same-process branch 3 times, most recently from fbf2c1d to 2550ff9 Compare March 25, 2022 01:59
@paul-soporan paul-soporan force-pushed the perf/binaries-in-the-same-process branch from 2550ff9 to 0abb98e Compare March 25, 2022 02:02
@paul-soporan paul-soporan marked this pull request as ready for review March 25, 2022 02:25
@aduh95 aduh95 requested a review from arcanis March 25, 2022 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants