[Bug?]: Executing other scripts within a script causes unavoidable additional start-up #4640
Closed
1 task done
Labels
bug
Something isn't working
Self-service
Describe the bug
We have a large monorepo with a 4mb .pnp.cjs file.
When any
yarn x
command is executed, the startup time is between 1.5 and 2.5s (depending on the machine environment) which I assume is because of the large pnp file.You can test this with a simple package.json with scripts:
time yarn echo
:While this might not be a very big deal when you're just executing a simple script that runs a single command, when you start to have scripts that call other scripts, the problem compounds itself.
We often make scripts that execute multiple other scripts within the same package.json like:
or that call one script from another in succession to build a more complex command like:
What we did not realize is for every execution of
yarn
, we were incurring the cost of the startup time of yarn pnp.As you can see from the below reproduction steps, the more executions of
yarn
, the more the startup time multiplies.I can find no way around this right now.
I can see a few potential solutions to this problem:
yarn
) to load very quickly when already loaded in the same process. This would be the best option IMHO :)yarn
that is has some special handlings to not reload the .pnpjs. I think this would be the most ideal though I'm betting there's some major consequences to doing this that would be a big deal to avoid, but I thought I'd suggest it.Any other ideas? Am I missing something?
To reproduce
You need a pretty big monorepo or a package.json with a lot of dependencies. We have 500~. Something to make your .pnp.cjs pretty large (ours is 4mb)
Start by
yarn install
to generate your .pnp file then:time yarn one
:time yarn five
:time yarn six
:Environment
System: OS: macOS 11.6.5 CPU: (20) x64 Intel(R) Xeon(R) W-2150B CPU @ 3.00GHz Binaries: Node: 14.18.1 - /private/var/folders/hw/120lj3wj5rb1pmb_x_s5tjp40000gn/T/xfs-9b58a563/node Yarn: 3.1.1 - /private/var/folders/hw/120lj3wj5rb1pmb_x_s5tjp40000gn/T/xfs-9b58a563/yarn npm: 8.12.2 - ~/.nvm/versions/node/v14.18.1/bin/npm
Additional context
No response
The text was updated successfully, but these errors were encountered: