Does it make sense to minify code used in NodeJS?

前端 未结 4 1442
礼貌的吻别
礼貌的吻别 2020-11-30 01:35

I was wondering, since Clojure Compiler and UglifyJS not only optimize code for size but also for performance (although I think size is the main priority), would my node.js

4条回答
  •  我在风中等你
    2020-11-30 02:17

    In node, the main processing cost is I/O operations, not the actual JavaScript itself. So for example:

    fs.readFile(myFile, function (err, data) {
        processTheFile(data);
    });
    

    Here, the gap between calling readFile and the callback being fired will be several times longer than the length of time the callback takes. (If it's the other way round, you probably shouldn't be using node.)

    So optimising the processTheFile function for speed is pointless, because you're saving a small percentage of a very very small number.

提交回复
热议问题