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

Top 5 reasons to deploy VMware with Tegile

More from The Register

next story
PEAK APPLE: iOS 8 is least popular Cupertino mobile OS in all of HUMAN HISTORY
'Nerd release' finally staggers past 50 per cent adoption
Microsoft to bake Skype into IE, without plugins
Redmond thinks the Object Real-Time Communications API for WebRTC is ready to roll
Microsoft promises Windows 10 will mean two-factor auth for all
Sneak peek at security features Redmond's baking into new OS
Mozilla: Spidermonkey ATE Apple's JavaScriptCore, THRASHED Google V8
Moz man claims the win on rivals' own benchmarks
Yes, Virginia, there IS a W3C HTML5 standard – as of now, that is
You asked for it! You begged for it! Then you gave up! And now it's HERE!
FTDI yanks chip-bricking driver from Windows Update, vows to fight on
Next driver to battle fake chips with 'non-invasive' methods
DEATH by PowerPoint: Microsoft warns of 0-day attack hidden in slides
Might put out patch in update, might chuck it out sooner
Ubuntu 14.10 tries pulling a Steve Ballmer on cloudy offerings
Oi, Windows, centOS and openSUSE – behave, we're all friends here
prev story

Whitepapers

Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Getting started with customer-focused identity management
Learn why identity is a fundamental requirement to digital growth, and how without it there is no way to identify and engage customers in a meaningful way.
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?
New hybrid storage solutions
Tackling data challenges through emerging hybrid storage solutions that enable optimum database performance whilst managing costs and increasingly large data stores.
Mitigating web security risk with SSL certificates
Web-based systems are essential tools for running business processes and delivering services to customers.