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.

361 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

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