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.

282 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. http://touchscreen-automation.blogspot.com/

    This design is wicked! You most certainly know how to keep a reader amused.
    Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job.
    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

  2. Aeron Scalper

    Right here is the right blog for anyone who wants to understand
    this topic. You know so much its almost tough to argue with you (not that I really
    will need to…HaHa). You definitely put a brand new spin on a topic that’s been written about
    for ages. Great stuff, just excellent!

  3. Sarah Cornish

    I keep trying to subscribe to the Letters thing, but there’s nowhere to do so! After i sign in, under the MANAGE YOUR SUBSCRIPTION weblink, there’s only my Book Club subscription. How do I add the Letters thing for $5?

  4. teotihuacan en linea


    Como habrás notado, me he quedado leyendo hasta
    el último de los artículos que escribiste.
    Espero que esto te sirva como motivación de que estás
    haciendo un trabajo muy bueno. En lo personal, soy amante de los buenos textos y me gusta
    proseguir a las personas que poseen las habilidades de hacer
    llegar experiencias a través de las palabras. Por ello te dejo
    este comentario y para cerrar quisiera decirte que me ha encantado poder llegar a tu sitio.
    En hora buena!

  5. Michelle

    What SEO strategy will your Seo agency use to lift your rated?
    This is why SEO rankings are crucial. Also you will fiind many websites contain expenses URL.

  6. Maxbet

    Have you ever considered about including a little bit more
    than just your articles? I mean, what you say iis valuable and all.

    However imagine if you added some great images or videos to
    guve your posts more, “pop”! Your content is excellent but with pics and videos,
    this blog could certainly be oone off the most beneficial in its field.
    Amazing blog!

  7. commercial loans florida saint petersburg

    Have you ever considered creating an ebook or guest authoring on other websites?
    I have a blog based on the same topics you discuss and would love to have you share some stories/information. I
    know my audience would enjoy your work. If you’re even remotely interested, feel free
    to shoot me an e-mail.

  8. body rub orlando

    An outstanding share! I’ve just forwarded this
    onto a friend who was conducting a little research on this.
    And he in fact ordered me breakfast due to the fact that I stumbled upon it for him…
    lol. So let me reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending some time to talk about this subject here on your web page.

  9. tax domain name registration

    Thank you for every other informative blog. The place else may I get that kind of information written in such an ideal method?

    I’ve a venture that I’m just now working on, and
    I have been at the glance out for such information.

  10. sesardelaisla.com

    You should pay proper attention towards this article.
    It is also best to limit intake of juices which are high in sugars and acid; they could lead to tooth abrasion and gum recession. With the right ingredients, grilled Crab sandwiches are
    not only an added plus to your health but also
    provide a hearty and tasty meal during summertime and on any other day.

  11. Justin Hughes

    You really make it appear so easy together with your presentation however I to find this matter to be really one thing that I think I would by no means understand. It kind of feels too complex and extremely large for me. I am having a look ahead to your next publish, I will attempt to get the hang of it!

  12. Lauren

    Learn exactly what it straegy to be below average. The stream exiting the cave does create a good transfer.
    You might not bee perfesct ffor drive yourself since the cave is
    heavily protected and rightly so.

  13. mmo

    The striking settings – with their rich and humorous ecology, colorful and
    cosmopolitan races and fantastic, sometimes haunting atmosphere –
    are nicely varied and a pleasure to explore. ‘You’ve trusted us
    with your money so we can build a game, not line our pockets,’ he said.
    For those who have participated in MMO Game Launches, you know
    for the first week or 2 You will have to sit and wait
    for server queues (Some are an outrageous amount of times.

  14. about.me

    The minerals that are toxic are recognized and are very quickly taken out of the bloodstream by the liver and stored
    in various places in the attempt to keep them out of the brain where they may
    cause actual brain damage. These side effects are not
    serious but immediate medical treatment should be initiated if noticed.
    Some genetic errors lead to mild neuropathies with symptoms
    that begin in early adulthood and result in little, if any, significant impairment.

  15. best home coffee machine australia 2016

    Selecting the best coffee makers can be tough especially since the heightened demand for the product often causes coffee machine prices to skyrocket.
    These espresso machines are generally larger than a typical coffee pot so make sure you measure.
    For more on Home Office Organization read: Home Office Organization Tips.

  16. SBOBET

    Just wish to say your article is aas astounding. The clarity in your
    post is simply spectacular and i can aassume you are an expertt on this subject.

    Well wigh your permission let me to grab your RSS feed to keep up to date with forthcoming post.
    Thanks a million and please keep up the enjoyable work.

  17. Izetta

    All transistors are BC547 B or any other equivalent type,
    . The use of the latter has made it possible for manufacturers
    to produce solar panels into flexible rolls using print-like processing that equates to lower costs
    and easier installations. We will Are Next To The
    Border For To Make Your Border Moving & Storage Easy.

  18. http://www.foodspotting.com/2850564

    Toolkits containing a bike pump, tyre levers and a means to repair punctures are a must.

    You can choose between a recumbent bike, upright
    bike, and a spinning bike. They have test riders hop on bikes before they are released to the public and then allow for a bit of adjustability.

  19. lowe's corner shower stalls

    Blow it away and recharge your health at the charger on the
    wall. Step 15 – Connections concluded employing the Z Uni-Fit Kit.

    If in doubt, for additional comparability, stick masking
    tape to the wall vertically updating the spirit level and take it to the position where the shower head will be.

  20. storeboard.com

    Smith has pitched well, and contributed in a big way with the bat for Calais.
    Much of the curriculum in gym class focuses on movement or
    exercise. Mc – Vicar is the Blue Devils catcher, and the
    straw that stirs the drink offensively.

  21. new york fashion photographers

    This will enable you to gain more on your subscription and enjoy your life free of any
    DISH Pronto complaints. I bought a 35mm camera and began shooting pictures of just about everything.
    Having professional experience both as a model and an educator, gives Raidt Photography a unique frame of reference from the
    director’s point of view, and helps them to provide a comfortable environment for both aspiring and experienced

  22. https://musicbrainz.org

    This cantilevered structure looks like rocks rising up out of Bear
    Run creek. Give the pot a good shake before you finally open it.
    Mixed neoclassical architecture with traditional Bengali architecture, the Marble
    Palace Mansion in Kolkata, India is lavishly floored with
    marble inlay.


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