Optimizing Javascript Performance.

Hey Jeff,

Just going through my actions from the last F2F and remembered that one of
them was to send you open questions on javascript execution on mobile
devices to see if we could extract a little research from one of your grad.
students.

I'm sure there is much more that can be done with this and there is
potentially a significant amount of research that can be done around this,
but here are my first quick thoughts on the subject:


* With / Without javascript compilation ? (we recommend using a javascript
compiler / minifier without naming one in particular. It would be
interesting to run the below benchmarks with/without compilation and
quantify any performance increase).

* Building a large dynamic string (concatenation operator vs array.push ...
followed by array.join).

* Iterating over a string: string[i] vs string.charAt[i]

* Iterating over an array: for (var i in array) vs for (var i=0; i <
arr.length; i++)

* Iterating over a map.

* Defining class methods (I assume Class.prototype.method = function() { ...
} is still most preferred over this.method = function () { }

* Overhead of using closures ?
  function test() { var msg = 'alert'; window.setTimeout(function() {
alert(msg); }, 100);
  vs function alertmsg() { alert('alert'); } function test() {
window.setTimeout(alertmsg, 100); }

* Use of with operator.  ( This modifies scope change on older browsers and
is not recommended, but not sure if it's still an issue).

And probably a tonne of others.

Not sure if anything interesting will come out of this, but if someone is
interested in bench-marking so we can make recommendations on the relative
impact of such improvements in mobile browsers that might be useful.

Thanks,

Adam.

Received on Monday, 10 November 2008 16:19:21 UTC