Feeds

Mozilla orders Jäger shot for Firefox engine

Down the hatch, SpiderMonkey

SANS - Survey on application security programs

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

High performance access to file storage

More from The Register

next story
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Oh no, Joe: WinPhone users already griping over 8.1 mega-update
Hang on. Which bit of Developer Preview don't you understand?
Microsoft lobs pre-release Windows Phone 8.1 at devs who dare
App makers can load it before anyone else, but if they do they're stuck with it
Half of Twitter's 'active users' are SILENT STALKERS
Nearly 50% have NEVER tweeted a word
Internet-of-stuff startup dumps NoSQL for ... SQL?
NoSQL taste great at first but lacks proper nutrients, says startup cloud whiz
IRS boss on XP migration: 'Classic fix the airplane while you're flying it attempt'
Plus: Condoleezza Rice at Dropbox 'maybe she can find ... weapons of mass destruction'
Ditch the sync, paddle in the Streem: Upstart offers syncless sharing
Upload, delete and carry on sharing afterwards?
New Facebook phone app allows you to stalk your mates
Nearby Friends feature goes live in a few weeks
Microsoft TIER SMEAR changes app prices whether devs ask or not
Some go up, some go down, Redmond goes silent
prev story

Whitepapers

Securing web applications made simple and scalable
In this whitepaper learn how automated security testing can provide a simple and scalable way to protect your web applications.
3 Big data security analytics techniques
Applying these Big Data security analytics techniques can help you make your business safer by detecting attacks early, before significant damage is done.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Top three mobile application threats
Learn about three of the top mobile application security threats facing businesses today and recommendations on how to mitigate the risk.
Combat fraud and increase customer satisfaction
Based on their experience using HP ArcSight Enterprise Security Manager for IT security operations, Finansbank moved to HP ArcSight ESM for fraud management.