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.

191 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. Anette Sisomphou

    I merely want to show you that I’m really raw to online blogging and incredibly cherished your webpage. Quite possibly I am prone to save your blog post . You seriously have fabulous article writing. Like it for giving out with us your domain report.

  2. Deon Hillen

    We just want to tell you which I’m really fresh to writing a blog and very much loved your site. Likely I am most likely to remember your webpage post . You literally have superb article writing. Value it for telling with us your internet webpage.

  3. Darius Hardges

    My Partner And I really want to inform you you in which I’m really new to online blogging and extremely loved your review. Very likely I am prone to store your webpage post . You indeed have fantastic article subject. Be Thankful For it for share-out with us your web document.

  4. games to play at home

    I’m really enjoying the theme/design of your weblog.
    Do you ever run into any browser compatibility problems?

    A few of my blog readers have complained about my blog not
    working correctly in Explorer but looks great in Opera.
    Do you have any ideas to help fix this issue?

    my homepage games to play at home

  5. dominatrix island

    You can opt to create almost any kind of utilizable space
    from your loft. Every homeowner has an interest in home improvement.
    The list of US home improvement retailers would not be complete
    without including the largest one of them all.

  6. dominatrix sex

    Once you are done, turn it and again start for the next strip.
    Two liter bottles like those soft drinks come in are good for keeping virtually every
    little thing. The list of US home improvement retailers would not be
    complete without including the largest one of them all.

  7. sunlight readable display

    Youre so cool! I dont suppose Ive read anything like this before. So good to search out any individual with some original thoughts on this topic. realy thank you for starting this up. this site is one thing that’s wanted on the internet, somebody with a bit of originality. helpful job for bringing something new towards the internet!

  8. Bdhfz.Com

    Hair transplant surgery uses your existing hair and it is important for us plastic surgeons, that patients
    must have healthy growing hair at the back and sides of the head to serve as donor area.

    Dozens of shopping apps permeate the App Store,
    bringing shopping right to the palm of your hand.

    Talk things out with your medical professional beforehand.

    my webpage … top rhinoplasty surgeons southern california
    - Bdhfz.Com,

  9. bonus senza deposito

    Hi, I would like to voice my appreciation for your kind-heartedness giving support to those who need assistance with your field. Your very own commitment to getting the message all over had been quite advantageous and have all the time empowered many people.

  10. Run Fred

    I do trust all the ideas you’ve introduced in your post. They’re very convincing and can certainly work. Still, the posts are too quick for starters. Could you please lengthen them a bit from subsequent time? Thank you for the post.

  11. search

    I know this website gives quality dependent posts and additional stuff, is
    there any other web site which gives these kinds of information in quality?

  12. birthday parties in the twin cities

    Please forgive my bad English.Thanks for each of your work on this blog. My mum enjoys carrying out research and it is simple to grasp why. My spouse and i know all of the powerful form you offer powerful strategies on this blog and strongly encourage response from others on the subject then our child is in fact learning a lot. Enjoy the rest of the year. You’re performing a great job.

  13. minneapolis paintball park

    I sorry not speak good English.Undeniably 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 annoyed while people consider worries that they plainly don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks

  14. twin cities paintball fields

    I sorry not speak good English.hey there and thank you for your info – I have definitely picked up something new from right here. I did however expertise some technical issues using this website, as I experienced to reload the website a lot of times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I’m complaining, but slow loading instances times will often affect your placement in google and could damage your high quality score if advertising and marketing with AdWords. Well I’m adding this RSS to my email and can look out for much more of your respective exciting content. Make sure you update this again very soon..

  15. womens underwear

    Picking your perfect swimwear may very well be harder than you think.

    Then, the Sexy Fishnet Teddy Open Cup 4 Piece Set is often a sure shot solution to set your partner’s pulse racing.
    Firstly dimension is vital, whether it won’t fit perfectly it may
    feel and look awful it doesn’t matter how perfect her figure

  16. Veda

    In FIFA6 gone area unit the times once a striker can leave your defender contact the sphere
    once a uncomprehensible slide tackle. Driving in Mad Max feels
    a lot better than the last time I jumped into it, ass
    the fluidity of combat while driving, i.

    I recommend using formatons which have ttwo strikers and a minkmum of one quick one at this foor counters.

  17. gestapo

    I am planning to move to Australia permanently. Hopefully, my immigration process will be completed this year and I will move in the beginning of 2011. Can someone suggest some excellent resources and blogs about making the plans for settling in Australia?.

  18. seinfeld xxx

    Pretty component of content. I simply stumbled upon your site and
    in accession capital to claim that I get in fact loved
    account your blog posts. Anyway I will be
    subscribing on your augment and even I achievement you access consistently quickly.

  19. Asley

    Sorry for my English.Thanks for all of your efforts on this site. My mum delights in managing research and it is easy to see why. Many of us know all relating to the compelling mode you render precious guidelines through your website and therefore improve response from other people about this content while our own child is really discovering a lot. Take pleasure in the rest of the new year. Your performing a splendid job.

  20. earn extra money

    Thanks for the marvelous posting! I really enjoyed reading
    it, you are a great author. I will be sure to bookmark your blog and will often come back very soon. I want to encourage you continue
    your great writing, have a nice day!

  21. Joanne Oliver

    I merely hope to inform you you that I am new to having a blog and incredibly cherished your report. Quite possibly I am likely to save your blog post . You definitely have fabulous article blog posts. Value it for discussing with us your main url information

  22. sena sofia

    Very good site you have here but I was curious about if you knew of any discussion boards that
    cover the same topics discussed here? I’d really like to be a part of online community where I can get suggestions from other knowledgeable people that share
    the same interest. If you have any recommendations, please let me
    know. Thank you!

  23. Verla

    Hey there would you mmind stating which blog platform you’re workinng with?
    I’m going to start my own blog in the near future but I’m having a
    tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is becaus your design and style seems different then most blogs and I’m looking for something
    unique. P.S Apologies for being off-topic but I hhad to ask!


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="">