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.

373 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. Tristan

    eval(ez_write_tag([[250,250],’alteredgamer_com-square-2′]));.
    However, if you look at something like a Titan Class ship, which costs billions and takes months to build, the real world value is
    estimated at around $6,000. Ao – C has timing in its favor: with WOW treading water until its next expansion and while Wo – W: Wrath of the Lich
    King is delayed, there are a few months of opportunity for Ao
    - C to capture an eager audience and make them its own.

    My page: pokemon go hack android – Tristan
    -

    Reply
  2. Kasha Nierer

    Por desgracia poca gente tiene la empatía suficiente para ponerse en el lugar del técnico de clínica micro, y no los culpo, después de dejarse un pastón en los cantos de sirena del comercial, su producto no funciona/esta roto/problema imaginario/rellenar aquí motivo de queja Lo normal es que si el equipo presenta un problema en el plazo 1 año, mientras no sea un daño evidente (rotura de pantalla, plásticos, quemaduras por sobretensión, bichos (si, cucarachillas, alguno llega asi) SOFTWARE!!

    Reply
  3. kdf podatki rozliczenie podatku w austrii

    You have observed very interesting details ! ps nice site. “Recompense injury with justice, and recompense kindness with kindness.” by Confucius.

    Reply
  4. social dating

    Attractive component of content. I simply stumbled upon your website and
    in accession capital to say that I acquire in fact loved account your
    blog posts. Any way I will be subscribing to your feeds or even I success you access consistently quickly.

    Reply
  5. consumo electrodomesticos chilectra

    Después de contactar con nosotros (llamando al 91 777 52 53 91 777 52 53), nuestros tecnicos de lavavajillas, tecnicos lavadoras, tecnicos secadoras , tecnicos de hornos, tecnicos de vitroceramicas, tecnicos de frigorificos, tecnicos de termos, tecnicos de microondas, tecnicos de campanas y termos electricos, quedan por teléfono con el cliente (Usted) para poder pasar por su domicilio lo antes posible, revisar el aparato y dar el mejor presupuesto.

    Reply
  6. tabla de electrodomesticos y su historia

    El técnico encontrará en esta obra principios tecnológicos de física, mecánica, electricidad y otros varios que le ayudarán a calcular y resolver problemas técnicos, así como normas y consignas de seguridad, esquemas básicos de electricidad, neumática, hidráulica, fluidos en general, calefacción, refrigeración y ventilación. Es una obra que en su versión original ha alcanzado 42 ediciones, debido a su éxito y a lo imprescindible para cualquier profesional y técnico de los sectores de frío y calor. Este libro ayudará a descubrir y conocer los secretos prácticos de la refrigeración en general.

    Reply
  7. london vip escort

    The early carriers operated by tthe Royal Navy were equipped with a combination fighter-dive bomber aircraft called
    the Skua as well ass biplanes armed with bombs or torpedoes such as the famous Swordfish.
    The Kor, Kang, and Koloth bridge designs feature a
    spacious layout with multiple angled columns overhead. Tugboats
    aree used for the same reason, too pull ships or all seaa going structures thwt cannot move
    on their own.

    Reply
  8. Avril Wince

    Good ¡V I should definitely pronounce, impressed with your web site. I had no trouble navigating through all the tabs and related information ended up being truly simple to do to access. I recently found what I hoped for before you know it in the least. Reasonably unusual. Is likely to appreciate it for those who add forums or something, website theme . a tones way for your customer to communicate. Excellent task..

    Reply
  9. Doug Couch

    of course like your website but you need to test the spelling on quite a few of your posts. Several of them are rife with spelling issues and I in finding it very troublesome to inform the truth on the other hand I’ll definitely come back again.

    Reply
  10. الشيخ الروحاني

    Glorious weblog! I truly enjoy how it is simple on my eyes in addition towards the details are properly written. I am wondering how I might be notified every time a brand new post has been produced. I’ve subscribed to your rss feed which should do the trick! Have a nice day!

    Reply
  11. Adeline Gischer

    Thanks, I have recently been looking for info approximately this subject for ages and yours is the greatest I have discovered so far. But, what about the bottom line? Are you sure about the source?

    Reply
  12. como engravidar

    Este acompanhamento justifica os problemas de infertilidade como problemas de
    saúde, que depende não só do profissional de psicologia, mas de toda equipe multidisciplinar, um olhar especial sobre estes
    casos.

    Reply
  13. Elaine

    I have learn some just right stuff here. Certainly worth bookmarking for revisiting.

    I surprise how much effort you put to make such a fantastic informative site.

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