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.

479 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. Jeniffer Milsaps

    Hey very nice web site!! Man .. Excellent .. Amazing .. I’ll bookmark your site and take the feeds also…I’m happy to find numerous useful information here in the post, we need develop more strategies in this regard, thanks for sharing. . . . . .

  2. Leslie Wakeham

    Hiya, I’m really glad I have found this info. Nowadays bloggers publish just about gossips and internet and this is really frustrating. A good web site with exciting content, that is what I need. Thanks for keeping this web site, I will be visiting it. Do you do newsletters? Cant find it.

  3. Arnold Fulson

    It can be almost unthinkable to come across well-advised viewers on this issue, then again you seem like you are familiar with what exactly you’re writing on! Cheers

  4. Dusti Barreneche

    We just wish to tell you that I am certain beginner to writing a blog and absolutely liked your review. Very likely I am prone to remember your site post . You indeed have magnificent article topic. Appreciate it for share-out with us your blog post.

  5. Gilbert Gerundo

    It truly is practically unattainable to find well-advised americans on this theme, nonetheless you look like you realize those things you’re posting on! Appreciation

  6. Vicenta Darrup

    It truly is near extremely difficult to encounter well-educated people on this matter, although you seem like you be aware of what you’re covering! Many Thanks

  7. Jewel Navanjo

    I’m still learning from you, as I’m improving myself. I certainly liked reading all that is posted on your site.Keep the information coming. I loved it!

  8. Robena Yaney

    It’s nearly extremely difficult to find well-updated people on this subject, unfortunately you appear like you know those things you’re writing about! Regards

  9. Wayne Kozlowski

    It’s actually mostly not possible to encounter well-updated americans on this niche, but you look like you fully grasp those things you’re talking about! Gratitude

  10. joanna shields twitter

    You’re so cool! I don’t think I’ve truly read something like this before. So nice to discover someone with some original thoughts on this topic. Really.. thank you for starting this up. This web site is something that is needed on the internet, someone with a little originality!

  11. Bobette Firestein

    We just wish to show you in which I’m really novice to wordpress blogging and thoroughly adored your write-up. Quite possibly I am inclined to save your web post . You truly have amazing article reports. Love it for discussing with us your site write-up.

  12. Rocky Kizer

    It really is practically unthinkable to encounter well-advised readers on this area, still you seem like you fully grasp which you’re writing on! Regards

  13. Mack Mordaunt

    It certainly is near not possible to come across well-updated parties on this niche, still, you appear like you realize what you’re preaching about! Appreciation

  14. www

    After going over a few of the blog posts on your website, I honestly like your technique of blogging. I added it to my bookmark website list and will be checking back in the near future. Please visit my website too and tell me how you feel.

  15. www

    Aw, this was an extremely good post. Finding the time and actual effort to make a very good article… but what can I say… I hesitate a whole lot and never seem to get nearly anything done.

  16. Lon Kurk

    My Partner And I simply desire to advise you that I’m just new to putting up a blog and genuinely liked your webpage. Very likely I am probably to remember your post post . You certainly have fantastic article text. Be Grateful For it for share-out with us your internet page.

  17. Iesha Vanscoter

    It truly is practically extremely difficult to find well-aware readers on this area, regrettably you appear like you fully grasp exactly what you’re talking about! Gratitude

  18. Shenna Feehery

    It is actually nearly close to impossible to encounter well-informed parties on this issue, yet somehow you seem like you understand the things you’re revealing! Bless You

  19. Wilford Crater

    We just have to show you the fact that I’m really fresh to writing and really loved your information. Most likely I am prone to bookmark your webpage post . You certainly have memorable article material. Admire it for telling with us your url document.

  20. Alberto Soluri

    It can be mostly unthinkable to come across well-aware viewers on this issue, unfortunately you appear like you fully understand which you’re revealing! Gratitude

  21. Lonny Weingarten

    I really need to share it with you the fact that I’m just inexperienced to posting and genuinely valued your website. Quite possibly I am likely to store your webpage post . You truly have magnificent article stuff. Like it for expressing with us your internet post.

  22. Rich Tapp

    It certainly is nearly impossible to see well-advised readers on this theme, then again you come across as like you fully grasp what you’re indicating! Gratitude

  23. Chong Howes

    It truly is mostly extremely difficult to encounter well-educated men and women on this content, fortunately you look like you fully grasp those things you’re covering! Gratitude

  24. Temple Wandel

    It can be mostly impossible to see well-educated viewers on this niche, but you come across as like you are familiar with what exactly you’re raving about! With Thanks

  25. Donald Dalbec

    We simply wish to notify you which I’m really beginner to writing and utterly enjoyed your website. Probably I am going to save your blog post . You simply have fabulous article posts. Value it for swapping with us your internet report.

  26. Kaitlyn Hoeffer

    My Partner And I just hope to inform you the fact that I’m really new to writing and thoroughly admired your write-up. Most likely I am probably to save your article post . You truly have extraordinary article content. Acknowledge it for discussing with us your website write-up.

  27. Vernetta Wene

    It’s actually mostly not possible to encounter well-aware users on this matter, however , you look like you comprehend what exactly you’re preaching about! Many Thanks

  28. Amberly Keeter

    It’s near close to impossible to encounter well-qualified americans on this issue, in addition you seem like you understand those things you’re revealing! Regards

  29. Devin Vanstrander

    Might be mostly close to impossible to see well-advised users on this matter, however, you come across as like you know the things that you’re writing about! Thank You

  30. Emile Stimler

    It can be practically impossible to come across well-updated men or women on this matter, however you look like you are familiar with whatever you’re indicating! Appreciation

  31. Ardath Kebert

    It truly is practically not possible to come across well-informed men or women on this area, in addition you seem like you comprehend what exactly you’re preaching about! With Thanks

  32. Jamey Surowka

    It is actually nearly unthinkable to encounter well-educated men or women on this matter, still, you appear like you know those things you’re posting on! With Thanks

  33. Bert Pujals

    You’ll find it near impossible to come across well-advised readers on this niche, yet somehow you look like you are familiar with exactly what you’re posting on! Thank You

  34. Fernando Tegtmeier

    My Partner And I simply desire to share it with you in which I’m really fresh to writing and really adored your post. Likely I am probably to store your article post . You simply have magnificent article content. Admire it for sharing with us your domain document.

  35. Liliana Mosman

    It can be practically close to impossible to see well-updated men or women on this matter, fortunately you look like you realize those things you’re talking about! Regards

  36. Alan Foresta

    It truly is nearly not possible to come across well-advised individual on this issue, yet somehow you come across as like you know the things you’re revealing! Thanks A Lot

  37. Ned Higgons

    You’ll find it near impossible to come across well-qualified women and men on this subject, although you come across as like you be aware of whatever you’re covering! Thanks A Lot

  38. Alyssa Serrant

    It is actually near impossible to encounter well-qualified users on this subject, yet somehow you come across as like you know whatever you’re covering! Appreciation

  39. Edwina Ficht

    You’ll find it near impossible to come across well-updated men or women on this theme, still you look like you be aware of whatever you’re raving about! Many Thanks

  40. Leta Callander

    It can be practically unthinkable to find well-qualified users on this subject, nevertheless you come across as like you comprehend those things you’re covering! Thanks A Lot

  41. Karla Juergens

    I just want to inform you you in which I’m just novice to blog posting and completely adored your article. Likely I am likely to bookmark your web post . You really have magnificent article posts. Truly Appreciate it for discussing with us your web report.

Comments are closed.