Performance: Running npm
on Windows runs node
executable twice (which is slow), to find the prefix
#3088
Labels
Bug
thing that needs fixing
platform:windows
is Windows-specific
Priority 2
secondary priority issue
Release 7.x
work is associated with a specific npm 7 release
Release 8.x
work is associated with a specific npm 8 release
I'm not sure if this is feasible / easy to optimize, but when profiling some of our scripts, I noticed the following:
As a Windows user, when I run
npm
through git bash in my shell [1], or have a JS script which useschild_process.spawn()
which callsnpm run something
, I expect thatnode
executable will be run only once as a result of such command.However, invoking
npm
in both cases (either through Windows.cmd
or git bash compatible.sh
) runsnpm prefix -g
internally.So every time any
npm
command is run, the penalty of booting up anode.exe
executable happens twice (on my Dell machine it's about 600-700ms).It's not a huge issue in itself, but when relying on
scripts
inpackage.json
, especially when those scripts are compounded (i.e.npm run x
callsnpm run y
), this penalty of multiplenode
executable calls accumulates fast.Current Behavior:
Running
npm
through terminal orspawn
runsnode.exe
twice, incurring the penalty ofnode.exe
boot twiceExpected Behavior:
Running
npm
should ideally runnode.exe
only once.Or at least, in case of nested invocations, there could be perhaps some optimization: 2nd and further calls to
npm
could reuse an env var exported by the first, top-levelnpm
invocation? (i.e. avoid callingnpm prefix -g
more than once per lifetime of a top-level script)(Although I know it can be tricky to rely on the env var, because some script may change it at runtime and break things).
Steps To Reproduce:
C:\git\node_debug\index.js
with following contents:git bash
usingNODE_OPTIONS
to run the hook above on eachnode.exe
creation:C:\git\node_debug
Environment:
Windows 10 (git bash), node@12.22.1, npm@6.14.12 (but behavior will be same with npm@7.9.0 as it calls
npm prefix -g
too)The text was updated successfully, but these errors were encountered: