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. 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. Andrew Stewart

    This very blog is really awesome additionally informative. I have found helluva helpful stuff out of this blog. I’d love to go back over and over again. Cheers!

  5. 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!

  6. 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.

  7. revenge

    Sacrifices and choices are usually positioned upon them, with foods and drinks
    being most commonly used within the West.

    Feel free to suurf to my web-site: revenge

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

    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.

  9. 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.

  10. 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

  11. ibcbet

    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.

  12. 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!

  13. 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!

  14. 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.

  15. 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.

  16. 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

  17. 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
    you.

  18. 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.

  19. 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.

  20. Maria Duncan

    I actually wanted to construct a simple remark to express gratitude to you for those awesome points you are sharing here. My incredibly long internet search has now been rewarded with brilliant points to go over with my two friends. I would declare that we site visitors actually are unquestionably lucky to live in a perfect website with very many special people with interesting plans. I feel quite happy to have encountered the web page and look forward to some more fabulous moments reading here. Thanks a lot again for everything.

  21. sgsex

    Currently it sounds like Expression Engine is the preferred blogging platform available right now. (from what I

  22. waterfalls

    However, these gardens will take a lot more time and energy to create than koi
    waterfalls.
    Waterfall faucets are designed to fit with vessel sinks; after your first family conference, it helps
    to speak with a home design architect or hardware retailer to plan your remodel
    and choose your bathroom sink at the same time you choose your
    faucet. When first planning to learn how to build a
    waterfall and pond, there are two very important structures that you need to focus
    on first: the part of the pond where the water falls and the structure from which the water
    falls from.

  23. Phil Mathis

    hello!,I like your writing so a lot! percentage we be in contact more approximately your post on AOL? I require a specialist on this space to unravel my problem. Maybe that’s you! Having a look forward to peer you.

  24. bedsheets

    Everyone loves what you guys tend to be up too. Such clever work and reporting!
    Keep up the wonderful works guys I’ve incorporated you guys to blogroll.

  25. domain Info

    To begin with I had to read the books myself to see what kind of information I would
    need to succeed with very little money. Regardless of which approach you use, it’s important to be careful not to register a domain Info name for a product that is already trademarked, as the trademark owner may be able to unilaterally
    confiscate your domain without compensation. Example, if you register , you are
    given multiple extensions like ,.

Comments are closed.