Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Studying JavaScript Performance

Studying JavaScript Performance

This item in japanese

Performance issues can always be an unexpected gotcha when developing your latest and greatest web 2.0 application, and a lot of times performance problems surface through the most benign of operations. Recently Coach Wei has taken the task of doing a quick study of the cost of many different Javascript operations as well as the differences in performance across browsers. The results aren't really all too surprising.

As expected, eval is still evil, performing very slowly on all browsers. Of particular interest though is that eval doesn't seem to fair as bad on Safari, taking only 9.4ns as opposed to 172ns and 546ns on IE7 and Firefox, respectively. Shift and Join array operations are a drag on all browsers.

An interesting point result that stuck out, as expected, IE tends to fare worse than other browsers when it comes to performance, especially in crucial areas such as computed box model calculations, String manipulation, and HTML DOM operations. Also of interest (which we've seen before) is that DOM operations in general are costly across all browser versions, although newer releases have seen some improvement. However, using innerHTML still seems to outperform the equivalent DOM manipulation that would be needed to accomplish the same task.

Other notable aspects of the study:

  • Safari's pop array operation is signiffently slower than other browser implementations
  • calculating computed style and computed box model can be expensive... the guess is that this cost is due to properties on currentStyle being recalculated on each call
  • object creation and the “in” operation seem to run slower on Firefox than in other browsers

The table of his results are worth a look, and may provide some guidance in debugging performance bottlenecks of your own.

Rate this Article