Firefox Borrows a Bit of Safari's Magic to Speed Up JavaScript

Mozilla’s Firefox web browser was one of the first to optimize for today’s JavaScript-heavy web pages. Mozilla’s new Tracemonkey JavaScript engine — released with Firefox 3.5 — put the browser at the top of most page rendering speed tests. But lately, Google Chrome, Apple’s Safari and the coming Opera 10.5 have been beating Firefox at […]

Mozilla's Firefox web browser was one of the first to optimize for today's JavaScript-heavy web pages. Mozilla's new Tracemonkey JavaScript engine -- released with Firefox 3.5 -- put the browser at the top of most page rendering speed tests. But lately, Google Chrome, Apple's Safari and the coming Opera 10.5 have been beating Firefox at its own game.

Mozilla is hoping to change that with some new improvements to Tracemonkey that promise to make Firefox even faster -- particularly on JavaScript-heavy websites like Gmail or Facebook.

The new project -- JagerMonkey, as it's known -- is built on top of Tracemonkey and borrows its assembler from Apple's open source Nitro JavaScript engine. As JagerMonkey programmer David Mandeli writes on his blog: "we know [Nitro] is simple and fast from looking at it before... it's open-source, and it's well-designed C++, so it was a great fit."

The goal of JagerMonkey is to cover a couple of blind spots in Tracemonkey's JavaScript rendering process. Most JavaScript can be compiled "just in time," that is, optimized by turning it from JavaScript into much faster native code. When that's possible, Tracemonkey's performance matches that of Chrome, Safari and Opera.

However, not all of the web's JavaScript can be converted to native code the way Tracemonkey currently works. Mandeli has a detailed explanation of what sort of code doesn't work and why, but the short story is that when Tracemonkey doesn't kick in, Firefox is still rendering that code at the same speed it was in 2007 -- in other words, very slowly by today's standards.

JagerMonkey will change that, handling the code that the existing Tracemonkey engine cannot.

Of course it will be some time before JagerMonkey makes it into Firefox proper. In fact, as of right now it isn't even in the Firefox nightly builds. If you really must try it for yourself right now, you'll find a link to the source code on the Mozilla wiki.

So far, the project doesn't have a roadmap and the wiki page indicates that there are still many optimizations to be done, but when JagerMonkey finally lands, it may well put Firefox back on top in the web browser speed wars.

Photo: Wikimedia Commons, PD

See Also: