Feeds

Mozilla orders Jäger shot for Firefox engine

Down the hatch, SpiderMonkey

Secure remote control for conventional and virtual desktops

Mozilla is brewing a new extension to the Firefox JavaScript engine, hoping to fix a flaw in its setup that occasionally sends the open source browser back to 2007.

Dubbed JaegerMonkey, the new extension will operate alongside the much-ballyhooed TraceMonkey - an extension that debuted with Firefox 3.5 in June of last year - interpreting JavaScript code unsuited to "tracing." With Mozilla's current setup, code that can't be optimized with TraceMonkey is kicked back to an aging interpreter that runs JavaScript at speeds reminiscent of the dark ages before Firefox 3.5 or Google Chrome.

The JaegerMonkey project is only about two months old - and it's a ways from testing in a Firefox beta build - but a blog post from Mozilla programmer David Anderson says it's already providing a 30 per cent performance boost over that old interpreter on x86 machines.

TraceMonkey attempts to speed performance by detecting code loops and converting them into assembly language, but there are cases where this sort of "tracing" just doesn't work. "Loops can throw curveballs that cause tracing to stop," Anderson says. "Especially with recursion, or lots of nesting, it can be very difficult to build good traces on complex code."

When this happens, Firefox falls back on its older interpreter, which isn't quite up to snuff, as Anderson admits. "When tracing fails, we have to fall back to our old-school interpreter. At that point your JavaScript runs about as fast as it would in 2007-2008 (i.e. before Firefox 3.5, Safari 4, Chrome, etc)," he continues.

"That’s not acceptable, and we need to fix that. Trace compilation is still an active area of research (one which we’ll continue to work on) - but in the interim, we need to make sure our 'slow path' is at least as good as the competition."

Other JavaScript engines forgo tracing, compiling entire methods - as opposed to just loops - into assembly code. The Nitro engine used by Apple Safari and its WebKit open source base, for instance, uses this whole-method compilation setup. This means it can handle the sort of "curveballs" Anderson speaks of, but according to Mozilla, it can't match Firefox speeds when TraceMonkey does kick in.

With JaegerMonkey - or JägerMonkey - Anderson and fellow programmers Dave Mandelin, Luke Wagner, and Julian Seward are working to marry these two methods. TraceMonkey will still look to convert loops, but when it can't, JaegerMonkey will use the Nitro approach to speed code on its own, converting entire methods into assembly. "The question we’ve been asked, and we’ve been asking of ourselves, is: Why couldn’t we trace and keep going SUPER AWESOME FAST, and when tracing fails, fall back to STILL REALLY FAST?" he says.

"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."

The new project uses the same assembly code compiler used by Nitro. As Dave Mandelin points out in a blog post of his own, TraceMonkey uses its own native code compiler, known as nanojit, but this was deemed unsuited to use with JaegerMonkey.

"Nanojit does a fair number of compiler backend optimizations, like dead store elimination and common subexpression elimination, which allows to generate faster code, but makes it take longer to generate that code," he writes. "We don’t expect those optimizations to help much in the Jäger domain, so we wanted something simpler and faster."

And that means lifting from Apple's open source Nitro. "We know it’s simple and fast from looking at it before," Mandelin continues, "it’s open-source, and it’s well-designed C++, so it was a great fit."

This was then paired with a method compiler designed by Anderson. Running on Anderson's machine, the new setup provides that 30 per cent boost on x86 and a 45 per cent boost on x64.

The Mozilla programmers have yet to actually integrate JaegerMonkey and TraceMonkey, but they plan to do so this week. Eventually, Anderson says, the method compiler will be able to identify loops and send them to the trace compiler. And then, if the trace compiler decides the loops are too complex, it will send them back to the method compiler.

You can browse the JaegerMonkey wiki here, and the source code is here. JaegerMonkey is an addition Firefox's core JavaScript engine, still known as SpiderMonkey.

The ultimate goal, Anderson says, is to provide whole-method compilation that's at least on par with Firefox competitors, and the implication is that TraceMonkey - the fast path - would take Firefox beyond its competitors. But in a third blog post, Mozilla director of community development Asa Dotzler argues that as the major browser makers continue to mimic each other's techniques, we'll reach a kind of equilibrium where JavaScript execution approaches the speed of native code execution - no matter whose browser you're using.

"We're probably not far from a world where all of the browser vendors are sharing these performance techniques," he says, "and when we get there... I think we'll see this particular performance 'war' wrapping up with everyone winning." ®

The essential guide to IT transformation

More from The Register

next story
The Return of BSOD: Does ANYONE trust Microsoft patches?
Sysadmins, you're either fighting fires or seen as incompetents now
China hopes home-grown OS will oust Microsoft
Doesn't much like Apple or Google, either
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
This is how I set about making a fortune with my own startup
Would you leave your well-paid job to chase your dream?
Microsoft cries UNINSTALL in the wake of Blue Screens of Death™
Cache crash causes contained choloric calamity
Eat up Martha! Microsoft slings handwriting recog into OneNote on Android
Freehand input on non-Windows kit for the first time
Linux kernel devs made to finger their dongles before contributing code
Two-factor auth enabled for Kernel.org repositories
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
5 things you didn’t know about cloud backup
IT departments are embracing cloud backup, but there’s a lot you need to know before choosing a service provider. Learn all the critical things you need to know.
Why and how to choose the right cloud vendor
The benefits of cloud-based storage in your processes. Eliminate onsite, disk-based backup and archiving in favor of cloud-based data protection.
Top 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?