views:

62

answers:

4

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 difference, but we have megabytes of verbose javascript, so would, e.g. a 'minify' build step help overall performance?

+1  A: 

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.

Stefan Kendall
+1  A: 

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.

Jonas H
+1  A: 

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.

methodin
+1  A: 

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.

Magnar