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.

334 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!

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

    Reply
  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
    appreciated.

    Reply
  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 ;)

    Reply
  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
    regularly.

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

    Reply
  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!

    Reply
  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

    Reply
  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?

    Kudos!

    Reply
  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!

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

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

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

    Reply
  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!

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

    Reply

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