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.

479 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. สลอต

    Definitely considrr that which you stated. Your favorite justification seemed to be on the net the easiest factor to take into accout of.

    Isay to you, I definitely get annoyed whilst people think about
    concerns that they plainly don’t recognise about.
    Yoou controlled to hhit the nail upon the highest and defined out the entire thing without having side effect , other peoople can take a signal.
    Will probably be again too get more. Thanks

  2. caroline yang

    El Parlamento creó una comisión de investigación sobre las actividades del SREL con 13 diputados que han descubierto estupefactos en estos cuatro meses escuchas ilegales, topos, archivos desconocidos, intentos de enriquecimiento y un alud de irregularidades que amenazan con dinamitar este servicio secreto creado en 1960. La parte central de nuestra investigación es determinar cuántos electrones libres había en el servicio”, dice François Bausch, uno de los parlamentarios del grupo Verde que ha metido la nariz en las alcantarillas del servicio secreto. El servicio mejorará después de esta crisis”, augura una fuente oficial del SREL.

  3. da ga online

    Trực tiếp các giải thi đấu đá gà bạc tỷ tại trường gà Thomo Campuchia. Xem miễn phí các trận chọi gà đỉnh cao, kịch tính hấp dẫn. Chất lượng hình ảnh sắc nét, tốc độ cao, không giật lag, mang lại những phút giây thư giản xem đá gà thực thụ.

  4. Evo F5 Game

    Thank you for sharing your knowledge! I believe you should experiment with it on comparable issues. You’re disseminating valuable academic information.

  5. fidesz

    Fidesz. Közben kihozta új felmérését a Republikon, amely
    szerint Orbán Viktor ismertebb, de Márki-Zay Péter népszerűbb.
    A gyermekek védelme miatt is meg kell állítani
    a baloldalt, amely egyértelművé tette, hogy be akarja engedni az LMBTQ-aktivistákat az iskolákba, és el akarják venni a szülőktől azt
    a jogot, hogy ők nevelhessék fel a gyermekeiket – mondta a Fidesz kommunikációs
    igazgatója csütörtökön, az MTI-hez eljuttatott videónyilatkozatában. Az Állami Számvevőszék székházát a Közös Ország Mozgalom aktivistái szerdán narancssárga festékkel festették össze, ahogy ők fogalmaztak: „Fidesz-színűre” mázolták. Mint ahogy az elrettentést sem. Másrészt az sem kérdéses, hogy a nyugati országok vagy az Egyesült Államok is kereskedelmi kapcsolatokat folytatnak ezen országokkal. A Megafilm ugyanis nem nevezte a filmet a már 2018-ban megrendezett Magyar Filmhétre, ezen pedig többek között a rendező, Kostyál Márk is kiakadt. Az érdemalapú társadalom koncepciójának elvetése: nem a szaktudás, innováció, verseny, kockázatvállalás a siker alapja, hanem a vezetőhöz való lojalitás. Nem azért, mert tetszik vagy nem tetszik a tartalma, hanem ezért, mert látom, milyen kampány előzte meg, milyen közérdeklődésre tart számot, tehát meg fogják nézni az emberek. „Én leteszem a politikai batyumat a színház ajtajában” – fogalmazott, hozzátéve: nincs jobb-
    és baloldali mozinéző, csak mozinéző van, nincs jobb- és baloldali színháznéző, hanem színházkedvelő emberek vannak.

Comments are closed.