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.

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

  23. 8 ball pool unblocked

    A lot of people will tell you to alternate solid and stripe, solid and stripe.

    This simple rule insures that proper bat-to-ball contact is made.
    AWAY STRIKE LOCATION – The holder will move around a couple more feet to give the batter a ball to hit that is on the
    outer 3rd of the plate.

  24. new city games

    For very young players, these can be too much for them to understand know but
    with their father or mother leading and teaching them, it will not
    be too long for them to understand the concept
    and how the game is played. Kind of confusing in words,
    once you play it it’ll make sense, even if the idea still leaves you in wonder.
    There is no need for you to deal with throngs of traffic
    just to go to the park for shooting a couple of baskets.

  25. https://musicbrainz.org/

    Make sure you don’t have HTML errors – they don’t have to
    be visual to you to be seen by Google. Some
    things you may consider including in your mobile SEO practices are click to
    call, mobile coupons, store locators or barcode scanners.
    Successful and ethical SEO optimization partner can help business carries out a
    successful campaign for as long as the business is online.

  26. https://foursquare.com

    One can even store it in his own backyard with proper covering.

    Carboard boat race is held on a beach of New Richmond, Ohio.
    Rest assured that the quality will not be compromised with, irrespective of the
    duration and timings of your Sydney harbour cruise.

  27. Fatima

    Goa tour gives you an opportunity to enjoy the true local
    experience like Goa cuisine, tradition and folk
    music, fair festivals and religious sites. The famous Mysore
    Palace attracts tourists from all over the world during
    the Dussehra Festival. But you want to have a well
    rounded holiday trip to Orlando; you can always get a vacation package deal that offers all the things
    you may want to experience during your vacation.

  28. Stephaine

    What if the line is a personal or private one; what should
    you perform. The confessions of others could have been obtained in violation of
    law and ethics. Use grenades and ranged weapons with area
    attacks to wear away at the remaining guards.

  29. Rickey

    Hi, i rread your blog occasionally and i own a similar one and i was just
    wondering if you get a lot of spam feedback?

    If so how doo you reduce it, any plugi or anythig you can suggest?
    I get so much lately it’s driving me mad sso any help is very
    much appreciated.

  30. http://bestwritershere.iscookin.com

    Moreover, you might be suggested to use the Wild World Web.

    Do not just put out a 500 work article, and attempt to break it up
    into subheads and subsections. Article Writing Service knows good
    Content Writing Service and offers some of the best Content Writing at the
    best prices out today.

  31. roofmetal.doodlekit.com

    Some of these potential signs of trouble a Miami roofing
    contractor looks for includes:. In that way, you will
    have the confidence to say “no” if you find
    their offer not satisfying. These contractors have an in depth knowledge of the several roofing equipments
    and can also give you complete idea about the roofing installations.

  32. Emilio

    Then for those parents who are actually having more than one baby they can opt
    for multi children prams and pushchairs if they so
    wish. It should remain upright with a diaper bag hanging over the handles.
    Obviously you can buy your flowers from a local florist and take them to hand over in person, which is by far the best option.

  33. https://www.zotero.org/

    If you’re comfortable with a cleaning, you’ll be more than comfortable when the dentist
    has to do some other work on your teeth, but the best part is that you’ll
    have peace of mind. It often has more than 100 employees,
    union contracts, large insurance policies, millions of dollars in its bank accounts and
    lots of people looking over its shoulder. Many dentists offer differed payment plans and
    additional discounts.


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