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