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.

235 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. vitapulse side effects

    Thiѕ nutгіᥱnt іѕ ɑn antіߋҳіԀɑnt that һаs ⲟѵег tҺгеᥱ ԁοzеn antіoⲭіⅾаnt cҺеmiсаⅼѕ.
    ᎳҺеn tɦiѕ tʏpе ߋf
    cɦоⅼᥱѕtеrߋⅼ ߋҳіɗіzᥱѕ,
    іt сɑn attасɦ tο the աalⅼѕ օf bⅼοοԀ νеѕѕеⅼs cɑᥙsing
    heaгt Ԁіseаѕе.
    Οսг ƅօⅾy іѕ գᥙіtе
    ԝеⅼl aԀɑρtеd
    tо ԁеaⅼіng ᴡіtɦ aсiԁіϲ ϲօndіtіⲟns, bᥙt іt
    cаnnοt Ԁеаl ԝitҺ tҺе еxϲеsѕіνe ɑϲіɗic lᥱѵеⅼs.

    Ӎу ѡеbѕіtᥱ vitapulse side effects

  2. Steven Greene

    It’s topper credt card if you fold the credit accountthat was sound business exercises. And the other part about this is that it faresn’t feature an one-year rattling exchangeable really.

  3. Janis

    Real story: a little over a year earlier, a pal of mine asked me to help him pick an Android
    phone since he was tired of his iPhone.

  4. Colin Carr

    Heya superb website! Does running a blog such as this take a great deal of work? I’ve very little knowledge of programming however I was hoping to start my own blog in the near future. Anyways, should you have any suggestions or tips for new blog owners please share. I understand this is off subject nevertheless I just had to ask. Thank you!

  5. Liam Johnston

    Hello I am so delighted I found your webpage, I really found you by error, while I was browsing on Yahoo for something else, Anyhow I am here now and would just like to say kudos for a incredible post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read it all at the moment but I have saved it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the excellent job.

  6. ยานมคลีนิค

    An impressive share! I have just forwarded this onto a co-worker who had been doing a little research on this.
    And he in fact ordered me lunch simply because I found it for him…
    lol. So let me reword this…. Thank YOU for the meal!!

    But yeah, thanks for spending the time to talk about this matter here on your internet site.

  7. Felicity Russell

    What’s Happening i am new to this, I stumbled upon this I’ve discovered It positively useful and it has helped me out loads. I’m hoping to contribute & assist different users like its aided me. Great job.

  8. Yvonne Sanderson

    Wonderful goods from you, man. I’ve bear in mind your stuff prior to and you’re simply too fantastic. I actually like what you’ve got here, certainly like what you are saying and the way in which you are saying it. You make it entertaining and you continue to care for to keep it wise. I can’t wait to learn far more from you. That is actually a wonderful website.Here is my website clash of clans triche

  9. ibcbet

    Hello I aam so grateful I found your website, I really found you by accident,
    while I was browsing on Digg for something else, Regardless I am here now
    annd would just like to say cheers for a incredible
    post and a all round enjoyable blog (I also love
    the theme/design), I don’t have time to look overr it all at the moment but I have bookmarked it and also
    included yur RSS feeds, so when I have time I will be back to read more, Please do
    keep up the excellent work.

  10. Yajaira Raisler

    Thanks on your marvelous posting! I certainly enjoyed reading it, you happen to be a great author.I will be sure to bookmark your blog and will eventually come back someday. I want to encourage you continue your great posts, have a nice holiday weekend!

  11. sopot hydraulik

    I just like the valuable info you supply in your articles.
    I’ll bookmark your blog and take a look at once more here regularly.
    I’m rather sure I will learn lots of new stuff proper right here!
    Best of luck for the next!

  12. www.articlespy.com

    If there is a row of 7 coins together, the player who is moving can pronounce that
    it is a “run” and then the opponent must stake two more coins
    and throw the dice, if he gets a 7,11, or 12 he will then lose all 9 coins.
    Parents who have obtained books, maps, and other resources connected to games have
    reported their children are more engaged with learning, which can lead to a lifetime
    appreciation for history. With its ample imagination, beautiful graphics and simple design full of rich gaming content, Mold on Pizza is
    so lovable and challenging that no one will be able to resist it.

  13. Penelope Parsons

    Michael Bailey had Faith Kroll and her fiancee Jim Marcus as guest speakers for his human sexuality class. You could possibly be surprised how you can find enough live lesbians Webcams sites offering people like you the on the internet and virtual pleasure you seek.One in the many pleasures of life’s sex which is enjoyed by one and many types of.

  14. Nicola Anderson

    It’s good clean fun free of cost that is common in most cases.The control is simple, you will have a battery life to support extended play times. They have nice graphics, and also the time candy crush saga cheat they wish. As a result of the player to candy crush saga cheat move further in the design of retro-cool.Have a look at my site: Candy crush saga hacks cheats

  15. tens unit weight loss

    hi!,I really like your writing very a lot! percentage
    we keep in touch more approximately your article on AOL?
    I require an expert on this area to resolve my
    problem. Maybe that’s you! Taking a look forward to look

  16. Abigail MacDonald

    Have you ever considered writing an ebook or guest authoring on other websites? I have a blog centered on the same topics you discuss and would love to have you share some stories/information. I know my viewers would value your work. If you’re even remotely interested, feel free to shoot me an email.

  17. Rosemary

    If you were initially contaminated with genital herpes before your 3rd trimester
    or before you got pregnant, and you have no signs of an outbreak (or an upcoming outbreak) when your water breaks or your labor begins,
    you’ll have the ability to labor and try for a vaginal shipment.


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