perf: load binaries in the same process #97
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thespawn
indirection and considerably improving the startup time:The way it achieves this is by modifying
process.{argv,execArgv}
andprocess.mainModule
(and the module cache to make sure thatrequire.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.