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.

347 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. amedea.si

    Here with our device,a part of the largest hacks group HackReleases you possibly
    can generate limitless amounts of Gold,Elixir and Gems for Clash
    of Clans elixir exploit!

  2. vitroceramicas eficiencia energetica

    El Servicio técnico de reparación de secadoras Siemens ofrece a sus clientes rapidez y toda la garantía de una gran marca. SAT España Servicio Técnico Oficial, S.L. es un servicio técnico oficial regulado por la Comunidad Autónoma de Madrid, pero no es el servicio técnico oficial de la marca Siemens. Les agradecería me valorasen la sustitución de la goma de escotilla de una lavadora Siemens modelo WXLM973EE/07. Estoy interesada en saber si hay recambio del cajón de la verdura del frigorífico siemens KG-36 U 170 y que precio tiene. Necesito el repuesto de la goma de la escotilla , la redonda gris,de una siemens Siwamat xlp126x.

  3. Guillermo

    Hi, i read your blog occaszionally and i own a similar one and i
    was just wondering if you get a lot of spam remarks?
    If so how ddo you reduce it, aany plugin or anything you can recommend?
    I get so much lately it’s driving me mad so any support is very much

  4. best hammocks

    I’d like to thank you for the efforts you have put in writing this
    website. I really hope to check out the same
    high-grade content from you later on as well. In truth,
    your creative writing abilities has motivated me to get my own, personal blog now ;)

  5. IT Beheer

    I’ve been exploring for a little bit for any high-quality articles or weblog posts in this
    kind of house . Exploring in Yahoo I finally stumbled
    upon this website. Studying this info So i’m
    glad to show that I’ve an incredibly just right uncanny feeling I
    discovered exactly what I needed. I most definitely will make sure to do not overlook this site and provides it a glance

  6. Read more

    My family and I really hope to inform you you the fact that I am raw to having a blog and totally liked your review. Probably I am likely to store your site post . You seriously have extraordinary article material. Acknowledge it for giving out with us your internet site page.

  7. eviction notice

    My programmer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs. But he’s tryiong none the less.
    I’ve been using Movable-type on several websites for about a year and am worried about switching to another platform.

    I have heard great things about blogengine.net.
    Is there a way I can import all my wordpress posts into
    it? Any kind of help would be greatly appreciated!

  8. my web profile

    It certainly is almost not possible to come across well-updated users on this area, yet somehow you come across as like you fully grasp exactly what you’re writing about! Gratitude

  9. Donzilla,

    After I originally commented I seem to have clicked
    on the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails
    with the exact same comment. There has to be a way you can remove me from that service?


  10. 10bet italia

    I like the valuable information you supply for your articles.
    I’ll bookmark your weblog and test again right here frequently.
    I am moderately sure I’ll be told a lot of new stuff right
    right here! Good luck for the following!

  11. cash for houses dallas

    I think everything posted made a bunch of sense.
    But, what about this? suppose you were to write a killer title?

    I mean, I don’t wish to tell you how to run your website, however suppose you added something that grabbed folk’s attention?
    I mean JaegerMonkey – Fast JavaScript, Always!
    | Mystery Bail Theater is kinda plain. You ought to glance at Yahoo’s
    front page and watch how they create article headlines to
    grab viewers to click. You might add a related video or a related pic or two to get people excited
    about what you’ve written. Just my opinion, it could make your
    posts a little bit more interesting.

  12. Cabo Boat Charters,

    Excellent goods from you, man. I’ve understand your stuff previous to and you’re just too wonderful.
    I really like what you have acquired here, really like what you are saying
    and the way in which you say it. You make it enjoyable and you still care for to keep
    it sensible. I can’t wait to read far more from you. This is really a wonderful web site.

  13. italian jewelry

    I’m now not positive the place you are getting your info, but good topic.
    I needs to spend a while studying more or working out more.
    Thanks for excellent info I used to be on the lookout for this information for my mission.

  14. porn

    My partner and I stumbled more than here by a different web site and thought I may as nicely check things out. I like what I see so now i am following you. Appear forward to looking over your web page repeatedly. I am truly into sophie turner, models. Fantastic post and I would check back again soon!

  15. [email protected]:mail.custom-wp.com:110:[email protected]:ozzy1991:0

    En otros encuentros del día, Genoa cayó 1-zero
    en casa con Chievo Verona y Udinese igualó sin goles
    como local frente al Cagliari.

  16. Margert Throneberry

    Servicio Técnico Lg está especializado en la reparación, instalación y mantenimiento de todo tipo de averías que se presenten en su aire acondicionado Lg. Con el fin de alargar la vida útil de su equipo de aire acondicionado LG realizamos todas las intervenciones con recambios nuevas y garantizando la calidad de nuestro trabajo en la reparación aire acondicionado LG por escrito.

  17. Love

    It actually is perfect time to make several plans for the future and it truly is time to be happy. I’ve read this post and if I could I desire to recommend you couple of useful points or advice. Perhaps you can publish next articles referring to this post. I want to read more issues about it!

  18. jak podrywać dziewczyny

    Excellent post. I was checking constantly this weblog and I’m impressed! Extremely useful details specially the last part I care for such info significantly. I was seeking this particular information for a long time. Thank you and finest of luck.

  19. Stormy Cuffy

    Thank you much for providing people with an exceptionally pleasant probability to check tips from this site. It really is so excellent and also packed with fun for me personally and also my office partners to visit your site almost 3 times in a full week to study the fresh advice you will have. Not to mention, On the web just usually pleased for the magnificent thoughts served by an individual. Certain two ideas on this page are often the most beneficial we have all ever had.

  20. celtic jewelry

    Hi. Cool post. There’s an issue with your web site in firefox, and you may want to check this… The browser will be the market chief and a great section of people will pass over your wonderful writing because of this difficulty.

  21. Linson

    I recently wanted to write down a fast concept so that you can say thanks to anyone for those superb suggestions as well as suggestions you are displaying on this internet site.

  22. vao cmd368

    Thank you for all your valuable hard function on this internet site. Betty takes pleasure in engaging in research and it’s really obvious why. I learn all relating towards the lively way you render rewarding items on this weblog and even improve contribution from the others on this concept so my princess is without a doubt starting to learn a great deal of issues. Take pleasure in the rest of the year. You’ve got been performing a dazzling job.

  23. playboxie ps4

    Aw, it was an really excellent post. In thought I would like to set up writing related to this moreover – taking time and actual effort to create a really good article… but exactly what do I say… I procrastinate alot and also no indicates manage to go done.

  24. فروش آپارتمان

    I am just commenting to let you know of the perfect experience my wife’s princess encountered studying your web internet site. She picked up numerous details, most notably what it’s like to have an perfect helping character to have several a lot more extremely easily gain information of selected advanced topic matter. You undoubtedly exceeded our own expectations. Thanks for offering such effective, healthy, explanatory and in addition enjoyable thoughts on this topic to Gloria.


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