6 ms·
Ask HN: Why does Node.js start so slow?
time php -r 'echo 123;'
outputs:
123
real 0m0.031s
user 0m0.023s
sys 0m0.008s
time python3 -c 'print (123)'
outputs:
123
real 0m0.022s
user 0m0.019s
sys 0m0.004s
time node -e 'console.log(123);'
outputs:
123
real 0m0.578s
user 0m0.551s
sys 0m0.028s
Why is the node version more than 10 times slower than the PHP and Python versions?
- efortis 4y agoWhat's your output for: `which node` and `node -v` On my M1 Pro: python3 -c 'print (123)' 0.02s user 0.01s system 86% cpu 0.036 total node -e 'console.log(123)' 0.04s user 0.01s system 88% cpu 0.053 total
- FreeHugs 4y agowhich node: /usr/bin/node node -v: v10.24.0 And for you? When I install it from https://deb.nodesource.com/setup_16.x https://deb.nodesource.com/setup_16.x then I get: node -v: v16.15.0 And indeed, then the time goes down by a factor of 10: time node -e 'console.log(123);' Now outputs: 123 real 0m0.058s user 0m0.046s sys 0m0.013s
- JohnHaugeland 4y agoYou're measuring how slowly your computer follows symlinks
- FreeHugs 4y agoCan you elaborate?
- JohnHaugeland 4y agoTake your original setup. Run it. Time it. Now, using `which`, invoke it directly, instead of through the symlink. Time it again.
- raxxorraxor 4y agoI guess the reason is that the runtime of node is so much larger than that of Python and PHP. I think the Node runtime is already at > 50MB as a binary. I don't know how large Python and PHP runtimes are, but I know python is often stripped down to a few kilobytes for embedded systems. I guess if you preload the runtimes before executing these commands, the execution should be fairly similar for each one (near zero, more depending on I/O).