Saturday, August 23, 2008

Firefox to get massive JavaScript performance boost

Mozilla is leveraging an impressive new optimization technique to bring a big performance boost to the Firefox JavaScript engine. The code was merged today (but is not yet ready to be enabled by default in the nightly builds) and is planned for inclusion in Firefox 3.1, the next incremental update of the open-source web browser.

I discussed this new optimization strategy with Mozilla's VP of engineering Mike Shaver and Mozilla CTO Brendan Eich, the creator of JavaScript. They are concerned that sophisticated web applications are being held back by the limitations of JavaScript interpreter performance. They aim to improve execution speed so that it is comparable to that of native code. This will redefine the boundaries of client-side performance and enable the development of a whole new generation of more computationally-intensive web applications.

They are "getting ready to take JavaScript performance into the next tier" with a radically innovative optimization tactic called tracing that has already produced performance improvements ranging between 20 and 40 times faster in some cases. They believe that this is just the beginning of what can be accomplished with tracing, and they expect to be able to achieve even better speed as the work continues.

The theories behind tracing optimization were pioneered by Dr. Michael Franz and Dr. Andreas Gal, research scientists at the University of California, Irvine. The tracing mechanism records the path of execution at runtime and generates compiled code that can be used next time that a particular path is reached. This makes it possible to flatten out loops and nested method calls into a linear stream of instructions that is more conducive to conventional optimization techniques. Tracing optimization is particularly effective in dynamic languages and also has a very light memory footprint relative to alternative approaches.

Mozilla already incorporated tracing optimization into Tamarin, a next-generation JavaScript runtime engine that leverages Adobe's ActionScript virtual machine. Tamarin, however, still lacks maturity and doesn't yet deliver significant performance gains—partly because Tamarin's ActionScript heritage means that it is optimized for efficient execution of code with type annotations. Tamarin is a long-term project and won't be ready until Firefox 4.


SpiderMonkey art by Shane Lewis

To get a real-world performance increase right now, Mozilla has adapted the tracing technology and Adobe's nanojit so that they can be integrated directly into SpiderMonkey, the JavaScript interpreter that is used in Firefox 3. This has produced a massive speedup that far surpasses what is currently possible with Tamarin-tracing. In addition to empowering web developers, the optimizations will also improve the general performance of the browser itself and many extensions because many components of the program are coded with JavaScript.

Bringing more power to client-side scripting will move the web forward and create new opportunities for web developers. Eich says that Mozilla wants to "get people thinking about JavaScript as a more general-purpose language" and show them that "it really is a platform for writing full applications."

Apple has also been implementing some extremely impressive JavaScript performance improvements with its compelling SquirrelFish virtual machine engine, which will be included in Safari 4. Like Mozilla, Apple says that the current performance gains delivered by the latest optimization techniques only scratch the surface of what is possible.

JavaScript isn't just a clumsy solution for client-side form validation anymore. While the implementors are aggressively addressing JavaScript's performance limitations, the ECMAScript standards community is making progress on addressing some of the language's historical syntactic weaknesses. The addition of some rather nice Pythonic sugar in JavaScript 1.7 and 1.8 is a great start, and the recent emergence of consensus in the standards community on the future of ECMAScript lifts some of the roadblocks that had prevented those efforts from going further.

With so much forward momentum and rapid evolution, JavaScript appears capable of meeting the demand for a more robust web programming platform. As more applications shift into the cloud, these capabilities will be essential for building the future of the web.


Digg del.icio.us Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy

No comments: