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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

pnpm runs scripts with notable delay compared to yarn and npm #3409

Open
ebeloded opened this issue Apr 29, 2021 · 9 comments
Open

pnpm runs scripts with notable delay compared to yarn and npm #3409

ebeloded opened this issue Apr 29, 2021 · 9 comments

Comments

@ebeloded
Copy link

ebeloded commented Apr 29, 2021

pnpm version: 6.2.1

pnpm offers great developer experience, for which I am very grateful 馃檹馃徎. However, I noticed that running scripts with pnpm is visibly slower than running them with yarn or npm. For example, a simple echo with pnpm finishes in 0.5s, whereas yarn gets back in 0.2s.

// package.json:
{
  "scripts": {
    "echo": "echo test"
  }
}
> time pnpm echo

pnpm echo  0.52s

> time yarn echo

yarn echo 0.18s

This is not a feature request per se, but rather a request for improvement. Hopefully, the run performance can get much closer to a direct script call.

The floor seems to be at ~0.05s for me with this setup:

// echo.js
const { exec } = require('child_process')

exec('echo hello', (err, stdout) => {
  console.log(`${stdout}`)
})
> time node echo.js
node echo.js  0.05s
@zkochan
Copy link
Member

zkochan commented May 2, 2021

The best solution would be to wrap pnpm with some native code (Rust, Reason, Go?) and use it to run scripts.

An easier to implement solution would be to add some code to pnpm.cjs that will load a smaller bundle of code when scripts should be executed.

@zkochan
Copy link
Member

zkochan commented May 15, 2021

I have published an experimental version of pnpm, where I bundled pnpm with pkg. It is published as @pnpm/beta.

This version of pnpm is much faster at startup.

the pnpm version bundled with pkg:

[zoltan@fedora inb]$ time pnpm f

> inb@1.0.0 f /home/zoltan/src/sandbox/inb
> echo hi

hi

real    0m0.183s
user    0m0.159s
sys     0m0.030s

the pnpm version that is NOT bundled with pkg:

[zoltan@fedora inb]$ time pnpm f

> inb@1.0.0 f /home/zoltan/src/sandbox/inb
> echo hi

hi

real    0m0.475s
user    0m0.446s
sys     0m0.036s

@ebeloded
Copy link
Author

Cool idea.

Couldn't get it installed on Mac:
image

@zkochan
Copy link
Member

zkochan commented May 15, 2021

I did not build an artifact for macOS yet.

@ebeloded
Copy link
Author

I also tried in a Docker container:

FROM node:12-slim
RUN npm i -g @pnpm/beta

image

@ebeloded
Copy link
Author

ebeloded commented May 15, 2021

Oh. Got it. You only built an artifact for win, right? This is cool.

Are there any drawbacks to using pkg?

@zkochan
Copy link
Member

zkochan commented May 15, 2021

There are currently two artifacts. For linux-x64 and win-x64

https://github.com/pnpm/pnpm/tree/main/packages/artifacts

so I think it should work in that docker image. Seems like there is issue with npm. Try to install with sudo. Or try to install it not globally but in some directory

@zkochan
Copy link
Member

zkochan commented May 15, 2021

I hope pkg has no drawbacks because I have big plans: #3434

@zkochan
Copy link
Member

zkochan commented May 16, 2021

I released an artifact for macOS x64 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants