npm / node-which

Like which(1) unix command. Find the first instance of an executable in the PATH.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

160x slower than GNU which (~500ms vs. 3ms)

rlue opened this issue · comments

I had this installed on my system without even realizing it (it's hidden somewhere in the dependency tree for taskbook), and it was causing tremendous, very difficult-to-debug delays in a separate, totally unrelated, non-Node program (GNU pass).

time which was reporting 500ms for this utility compared to 3ms for GNU which on a 4th-gen Core i5 Linux box. For some reason, it runs very fast on a comparably specced machine I own. Happy to help debug, if you tell me what you need.

Scratch that; on further inspection, it looks like node just takes that long to load. I inserted a console.log debug statement at the top of the which script, and it shows that 500ms+ pass before the first line of the script is evaluated:

#!/usr/bin/env node
console.log((new Date().getTime()) - Number(process.env.START))
var which = require("../")
...
$ START=$(($(date '+%s%N')/1000000)) which which
570
/usr/local/share/.config/yarn/global/node_modules/.bin/which

I don't suppose there's any chance you'd know offhand why node is so slow?

I'm not sure offhand, I mean, apart from "it does a bunch of stuff". I'd love to see node's startup time come down.

@isaacs thanks for the feedback; I did some more digging on my own, and it looks like nvm node runs fast enough (70ms); it's only the official APT package provided by nodesource.com that's slow. Filed an issue on their repo, as referenced in the timeline above.