mattsanchez — 2012-10-25T17:15:13-04:00 — #1
I just watched a short presentation by Douglas Crockford where he said that the benefits of optimizing JS were insignificant. His reasoning was that the DOM is so inefficient and spends so much time rendering layout, style, etc, that it negates the benefits of optimizing code. Is this true?
paul_wilkins — 2012-10-25T18:48:43-04:00 — #2
Have you heard the phrase about premature optimization being the root of all evil? Before optimizing, figure out where the slowdowns and bottlenecks are, so that your optimizations can then be effectively targeted at dealing with the actual problem that is being faced.
logic_earth — 2012-10-25T18:49:52-04:00 — #3
felgall — 2012-10-25T21:29:18-04:00 — #4
Where the optimised version is just as quick to write and just as easy to read as the unoptimised version then using the optimised version still makes sense.
Where the optimised version results in less typing and easier to read code then there is even less reason for using the alternative.
Often using a slightly better optimised version means that you are using code that is easier to read and maintain.
So for example I'd reference the first data row in a table using:
because it is shorter to type and easier to read and the fact that the shorter version is actually a more efficient way to do the access iin most modern browsers is an added benefit rather than a reason.