W3C home > Mailing lists > Public > public-bpwg@w3.org > November 2008

Optimizing Javascript Performance.

From: Adam Connors <adamconnors@google.com>
Date: Mon, 10 Nov 2008 16:18:35 +0000
Message-ID: <393b77970811100818u7612bc96q4f8c7a1da6f98757@mail.gmail.com>
To: Jeff Sonstein <jeffs@it.rit.edu>, Mobile Web Best Practices Working Group WG <public-bpwg@w3.org>
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

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:42:59 UTC