Monday 25 February 2019

node binaries take 500ms just to load?

I just spent a couple weeks scratching my head over a problem with a program totally unrelated to Node, which was caused by node which. Basically, node which was installed globally, so it was overriding /usr/bin/which. GNU which runs v. fast (3ms) compared to node which (500ms+).At first, I thought the problem was with node which itself, so I filed an issue on GitHub. Then, when debugging the issue, I realized that it takes over 500ms before the first line of the script is even evaluated:```javascript!/usr/bin/env nodeconsole.log((new Date().getTime()) - Number(process.env.START)) var which = require("../") ... ```sh $ START=$(($(date '+%s%N')/1000000)) which which 570 /usr/local/share/.config/yarn/global/node_modules/.bin/whichI'm on a 4th-gen Core i5 desktop Linux box and seeing the same behavior on a similarly specced laptop (ThinkPad T460). Is this just how node is, or is there some way to improve the initial load time?

Submitted February 26, 2019 at 03:12AM by ryanlue

No comments:

Post a Comment