Javascript performance and minification
Does anyone know if there's any benefit in 'minifying' locally-stored javascript code to squeeze more performance out of the javascript engine?
Usually minification is done to reduce bandwidth requirements/costs, or obfuscation, but would there actually be any performance benefits?
In other words, does this code:
let i=[1,2,3,4,5,6];let r=i.map(function(e){return e*e;});
..run faster than this code:
let inputData = [ 1, 2, 3, 4, 5, 6];
let squaresOfInputData = inputData.map( function square(element)
{
return element * element;
}
Of course algorithm choice will make the biggest diff开发者_高级运维erence, but we have megabytes of verbose javascript, so would, e.g. a 'minify' build step help overall performance?
You'll have a smaller file to load into memory for parsing, but the gains would be minuscule on a modern computer. You are likely better off with easy production debugging and a simpler build process.
It should, but probably not by much.
Why not profile both ways and see the actual gains? That's the only real way to know.
Yes, there will be a (most likely tiny) improvement in parsing speed from having fewer characters to parse, but the code will not run any faster.
Minification is to primarily save load time and bandwidth, so in that regard it would help immensely. I can't imagine you'd see any real difference in performance unless you are really running very intense code. The large fruit here is script size, any performance gain is just icing on the cake.
精彩评论