缩小NodeJS中使用的代码是否有意义? [英] Does it make sense to minify code used in NodeJS?
问题描述
我很想知道,因为Clojure Compiler和UglifyJS不仅可以优化代码的大小而且还可以优化性能(虽然我认为大小是主要优先级),如果它的缩小,我的node.js应用程序会运行得更快吗?我知道它可能取决于应用程序,但我一般都会问这个。
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 app run faster if it was minified ? I know it may depend from app, but I'm asking this in general.
推荐答案
在节点中,主要处理成本是I / O操作,而不是实际的JavaScript本身。例如:
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);
});
这里,调用 readFile
和被触发的回调将比回调所花费的时间长几倍。 (如果情况相反,你可能不应该使用节点。)
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.)
因此优化 processTheFile
速度函数毫无意义,因为你节省了一小部分非常小的数字。
So optimising the processTheFile
function for speed is pointless, because you're saving a small percentage of a very very small number.
这篇关于缩小NodeJS中使用的代码是否有意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!