Over a million developers have joined DZone.

JaegerMonkey Adds Fuel to Firefox

· Web Dev Zone

Make the transition to Node.js if you are a Java, PHP, Rails or .NET developer with these resources to help jumpstart your Node.js knowledge plus pick up some development tips.  Brought to you in partnership with IBM.

The race to be the fastest browser is now focused on having the most efficient JavaScript engine.  JS engines such as Google's V8 and Opera's revamped Carakan are locked in an escalating competition to dominate the benchmarks.  In the increasingly fierce Browser Wars, TraceMonkey is Firefox's secret weapon, but in some situations it can't do very much.  That's why Mozilla is developing a new method JIT compiler for SpiderMonkey, the Firefox JavaScript engine.  The new compiler, called JaegerMonkey (or JägerMonkey), is an attempt to bring the baseline performance of Firefox up to current standards when the TraceMonkey extension can't work its magic.  Mozilla says the initial performance tests for the new model look promising.

                             
                                                                      Image Source: Maximim PC

Firefox can be extremely fast when the TraceMonkey JS optimizer is able to work.  It detects loops and converts them into a high-performance assembler code in a process called "tracing".  The only catch is that when the JavaScript doesn't contain many loops or something causes the tracing to stop, the performance goes down the drain.  This is because SpiderMonkey falls back to an older, slower interpreter that runs at speeds found in 2007-2008 browser versions.  Complex code with recursion or a lot of nesting, for example, can cause tracing to stop.  Compilers such as WebKit's interpreter and Safari's Nitro don't use tracing, but instead convert whole functions into assembler code.  These two compilers perform better than SpiderMonkey when tracing doesn't work.

Mozilla developer David Anderson says this performance pitfall is unacceptable.  In response, the Firefox developers have created JaegerMonkey, which is a method JIT compiler that provides inline threading for SpiderMonkey.  Inline threading is just a baseline whole-method JIT that does dynamic-language-JIT-oriented optimizations (e.g. PICs and specialization of constant operands) and doesn't perform many traditional compiler optimizations.  Anderson says TraceMonkey and Jaeger will be tightly integrated to combine the concepts of tracing and whole function conversion.  First JaegerMonkey will convert functions into generic assembler code.  Then if it detects any loops, it will send them to TraceMonkey for further optimization.  If it doesn't detect loops, then it will bypass the slow interpreter and directly execute the code.

David Anderson explains, "We’re taking the tried-and-true approach of other vendors, and bolting trace compilation on top.  Once the two are interacting seamlessly, you’ll have a much more consistent – and fast – JavaScript performance experience.  We’ve barely started and the results are already really promising."  Anderson said the benchmarks for running SunSpider on his machine reveal that the whole-method JIT compilation is 30% faster than the current interpreter on x86, and it is 45% faster on x64.  Anderson also notes that this performance was achieved without much optimization work.   JaegerMonkey is currently using Apple's Nitro JavaScript JIT compiler instead of SpiderMonkey's Nanojit compiler.  JagerMonkey developers hope to put Firefox on par with other browsers when tracing isn't an option, and then blow them away when it is available.  Anderson said the JaegerMonkey team plans to integrate tracing next week.

You can get the JaegerMonkey source code from this makeshift repository.

Learn why developers are gravitating towards Node and its ability to retain and leverage the skills of JavaScript developers and the ability to deliver projects faster than other languages can.  Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}