JaegerMonkey – Fast JavaScript, Always!

Mozilla’s JavaScript optimizer, TraceMonkey, is pretty powerful. It carefully observes loops and converts them to super-fast assembly. We call this “tracing”.

That’s great and all, but there’s a problem: sometimes tracing doesn’t work. Loops can throw curveballs that cause tracing to stop. Especially with recursion, or lots of nesting, it can be very difficult to build good traces on complex code.

Other JavaScript engines, such as Nitro (present in WebKit/Safari), take a simpler approach. Instead of compiling loops to assembly, they compile entire methods (functions) to assembly. The generated code is much more generic than tracing, so while it is not as fast, it can handle any curveball.

What we’ve found is that when tracing works, we’re faster than the generic approach. But 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).

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.

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?

Enter JaegerMonkey.

Our new project, JaegerMonkey (or JägerMonkey), has exactly this in mind. 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.

Dave Mandelin, Luke Wagner, Julian Seward and I have been sprinting the past few weeks to get something basic working. To emit actual machine code, we’re using some very pretty classes (“macro assembler”) from Nitro. That’s been a real treat; it’s well-abstracted and C++ish, and allowed us to get to work on the actual compiler very quickly.

Our compiler is simple so far. Before interpreting a method, we translate each bytecode into some pretty generic assembly. For example, an “ADD” opcode will emit assembly that can handle both fast cases (adding two numbers) and slow cases (adding, say, an object and a string).

Contrast this to tracing, where the types are known, and pinned, statically – it does not need to handle any extra cases that might come up. In the whole-method compiler, the generated code must handle all unexpected variations in control or type flow.

After the function is compiled we execute it right away – the interpreter is skipped entirely.

Early Progress.

We’ve barely started and the results are already really promising. Running SunSpider on my machine, the whole-method JIT is 30% faster than the interpreter on x86, and 45% faster on x64. This is with barely any optimization work! When we integrate tracing next week, we’ll already start to see the benefits of both working together.

For a more in-depth study, Dave Mandelin has blogged about our early performance gains, what’s done, up-and-coming, etc.

As we move forward, the two compilers will be tightly integrated. The method compiler will be able to identify loops and invoke the trace compiler. The trace compiler, if it decides a method is too complex to inline, may decide to invoke the method compiler.

The future of SpiderMonkey is bright and shiny, and we’ll be talking more about the project as it reaches major milestones.

In the meantime, if you are interested in learning more, I invite you to look at JaegerMonkey on the Mozilla wiki, and our makeshift source code repository. We also hang out in #jsapi on irc.mozilla.org.

92 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. perrgjx

    Football head protection decals like these from Pro Helmet Decals are the symbol of the team. They are their brand and a powerful manifestation of team colors regarding players and proponents alike.
    I have build this lens to share my collection of free things with you since the freebies offers i have come from different countries i have first send out them to my family and friends who came up with the idea to place them on a website.
    Baby Pittsburgh Penguins NHL Hockey Tops for Sale – Low cost Custom Penguins Sports ApparelPittsburgh Penguins NHL Jerseys for Infants and Toddlers Online

    Reply
  2. ROBBIE

    Great to have the list, will work my way through the different links. Good to see a healthy amount of blogging. Just started blogging myself. Would love to get a debate going so any comments are welcome.

    Reply
  3. parking lotnisko poznan

    I want to express some thanks to this writer for rescuing me from such a crisis. After exploring throughout the the net and finding tips which are not pleasant, I thought my life was over. Existing minus the strategies to the problems you have solved by means of your good review is a critical case, and ones that could have badly affected my career if I had not encountered the blog. Your good know-how and kindness in touching almost everything was precious. I am not sure what I would’ve done if I hadn’t encountered such a stuff like this. I can also at this time relish my future. Thanks so much for the skilled and result oriented help. I will not think twice to suggest your blog post to any person who should get direction on this area.

    Reply
  4. 24 Hour Electrician Calgary Alberta

    You are so awesome! I do not think I’ve truly read anything like that before. So wonderful to discover someone with some genuine thoughts on this topic. Seriously.. thanks for starting this up. This web site is something that is required on the internet, someone with a little originality!

    Reply
  5. http://volumepills-online.com

    The very next time I read a blog, Hopefully it does not disappoint me just as much as this one. I mean, Yes, it was my choice to read through, but I genuinely thought you’d have something useful to say. All I hear is a bunch of complaining about something that you can fix if you were not too busy seeking attention.

    Reply
  6. administratiekantoor

    Hi there! This blog post could not be written any better! Looking through this post reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will send this article to him. Pretty sure he will have a very good read. Thank you for sharing!

    Reply
  7. taxi driver

    You’ve made some really good points there. I checked on the internet for more info about the issue and found most people will go along with your views on this web site.

    Reply
  8. truckar

    This continuously amazes me precisely how bloggers for example your self can find some time as well as the dedication to carry on creating fantastic blogposts. Your blog isgood and 1 of my personal must read weblogs. I just wanted to thank you.

    Reply
  9. al arab hotel video

    Whats up very cool blog!! Man .. Excellent .. Wonderful .. I will bookmark your site and take the feeds additionally?
    I am glad to search out numerous helpful info here within the submit,
    we need develop more techniques in this regard, thank you for sharing.

    . . . . .

    Reply
  10. Walking Stilts

    Thanks for expressing your ideas here. The other element is that if a problem appears with a computer system motherboard, folks should not take the risk involving repairing that themselves because if it is not done right it can lead to irreparable damage to an entire laptop. It is almost always safe just to approach the dealer of that laptop for that repair of the motherboard. They will have technicians that have an skills in dealing with notebook motherboard troubles and can have the right prognosis and undertake repairs.

    Reply
  11. industrial tapes

    I intended to draft you this little bit of note to say thank you again for these remarkable basics you have shared in this case. This has been certainly generous of you to give easily precisely what a lot of people would’ve marketed as an ebook to get some money on their own, especially considering the fact that you might well have done it if you ever decided. Those principles likewise acted to be a great way to be aware that other individuals have similar zeal just as my very own to understand much more concerning this condition. I’m certain there are numerous more enjoyable times in the future for individuals that scan through your site.

    Reply
  12. Donn Abby

    Thank you for another informative web site. Where else may I get that type of information written in such a perfect approach? I’ve a challenge that I’m simply now running on, and I have been on the look out for such info.

    Reply
  13. Nancee

    I’ve been surfing online more than 3 hours today, yet I never found any interesting article like yours.
    It’s pretty worth enough for me. In my opinion, if all site owners and bloggers made good content as you did,
    the internet will be a lot more useful than ever before.

    Reply
  14. Format: Spintax

    Hello there, simply become aware of your weblog thru Google, and found that it is really informative. I’m going to be careful for brussels. I’ll be grateful in the event you proceed this in future. Numerous people will probably be benefited out of your writing. Cheers!

    Reply
  15. 10km

    I sorry for bad English.Unquestionably believe that which you stated. Your favorite justification seemed to be on the internet the easiest thing to be aware of. I say to you, I certainly get irked while people think about worries that they plainly don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side-effects , people can take a signal. Will likely be back to get more. Thanks

    Reply
  16. Laticia Z. Dobler

    Thanks for your personal marvelous posting!
    I certainly enjoyed reading it, you might be a great author.
    I will make certain to bookmark your blog and will come back at some point.
    I want to encourage yourself to continue your
    great posts, have a nice morning!

    Reply
  17. Cierra Reano

    I came in this article from a search too. Looking for Frank Nastasi b/c I’ve been writing a blog post upon Soupy Sales. My Soupy images searches did NOT bring me to your internet site, although yours are the most fascinating soupy pix I’ve encounter.

    Reply

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">