npm / npm/cli

NPM startup time is 3 times slower than YARN

Open
#4,413 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

perf Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

I have 1.js:

console.log(1);

Startup time of it with NPM is longer than running it with YARN 3-4 times.


Here is the repo: https://gist.github.com/AlttiRi/ba7fbabca1953cba012506010aff8ff9
process-bench.js is for the convenient benchmarking.


Executing of this file with Node.js takes 55 ms:
node process-bench.js "node 1.js":

[exec start][node 1.js] 7
[data] 55
1

[exec end] 61

Executing of this file with NPM takes 871 ms:
node process-bench.js "npm start":

[exec start][npm start] 6
[data] 816

> start-time-demo@2.0.0 start
> node 1.js


[data] 871
1

[exec end] 888

What does NPM do 816 ms?


Executing of this file with YARN takes 287 ms:
node process-bench.js "yarn start":

[exec start][yarn start] 6
[data] 178
yarn run v1.22.17

[data] 220
$ node 1.js

[data] 287
1

[data] 294
Done in 0.13s.

[exec end] 305
Expected Behavior

It should work at least as fast as YARN.
Faster — better.

Ideally It should be a few (0-2) ms slower than when I run it directly with Node.js.
In this case you only need to parse the command line argument and run the script with node.
Technically you even not need to run node for npm, you can parse this simple case in a shell script.

But even 55 ms to run node for npm, 1-5 ms to parse the command line arguments and package.json, then 55 ms to run node for the script — 115-130 ms total will be nice.

Steps To Reproduce
  1. Download https://gist.github.com/AlttiRi/ba7fbabca1953cba012506010aff8ff9
  2. Run node process-bench.js "node 1.js"
  3. Run node process-bench.js "npm start"
  4. Run node process-bench.js "yarn start"
Environment
  • npm: 8.5.0
  • yarn: 1.22.17 (npm install --global yarn)
  • Node.js: v17.5.0
  • OS Name: Win 10
  • npm config:
"builtin" config from C:\Users\User\AppData\Roaming\npm\node_modules\npm\npmrc
prefix = "C:\\Users\\User\\AppData\\Roaming\\npm"
"user" config from C:\Users\User\.npmrc
node bin location = C:\Program Files\nodejs\node.exe
cwd = C:\Users\User\Downloads\1
HOME = C:\Users\User

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running process-bench.js from the linked gist with the documented node, npm start, and yarn start commands, using 1.js as the minimal script. Compare the timings and inspect the npm startup path to locate the reported overhead. Done means explaining or reducing the gap while preserving the npm start behavior and confirming the result with the same benchmark.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, performance, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.