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.

406 thoughts on “JaegerMonkey – Fast JavaScript, Always!

  1. Tristan

    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

  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!!

  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.

  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.

  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.

  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.

  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.

    1. Leonie

      Τhank you for the blog post. Brown and I have been saving for just a new guide on this topic and your writing has made all of us to save our moneү.
      Уour opinions really rezpоnded all our questions.
      In fact, greater than what we had аcknowledged previous to the
      tіme we ran into your fantastic bloɡ. Mү spouse
      and i no longer nurtture doubts and also a troubled mind because you have attended to the needs in this pоst.

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

    1. คอหวย

      I feel that is one of the so much vital information for me.
      And i am happy studying your article. But wanna statement
      on few general issues, The site taste is great, the articles is in point of fact great :
      D. Excellent job, cheers

  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.

  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!

  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?

  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

  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.

  14. mujeres desnudas en la playa

    Simply desire to say your article is as amazing. The clarity in your put up is
    just excellent and that i can assume you are an expert on this subject.
    Fine with your permission allow me to take hold of
    your RSS feed to stay up to date with drawing close post.

    Thanks a million and please keep up the enjoyable work.

  15. Vaughn

    Ha superado mis expectativas…. No esperaba que fuera a coincidir de tal manera con lo que necesitaba comprender. Te agradezco enormemente la información!

  16. Enrique

    Quisiera agradecer la oportunidad de ofrecer estos conocimientos que nos dejan mensajes tan significativos. A mi personalmente me ha llegado muchísimo al alma.

  17. Site

    Site – Wholesale Where To Get Cheap Football Jerseys Directory.
    You can Online where to get cheap jerseys online,Wholesale jersey plain,aj mccarron jersey,cheap custom jersey

  18. Monte Scialpi

    I would like to express my admiration for your kindness in support of all those that have the need for help with this particular area. Your special commitment to getting the solution up and down appeared to be pretty insightful and has truly allowed most people much like me to reach their pursuits. Your warm and helpful publication indicates a lot to me and additionally to my fellow workers. Regards; from everyone of us.

  19. FirstHarriett

    I see you don’t monetize your site, don’t
    waste your traffic, you can earn additional bucks every month
    because you’ve got high quality content. If you want to
    know how to make extra $$$, search for: Boorfe’s tips best adsense alternative

  20. Caldera Vaillant

    Me gusta disfrutar y visitar blogs, aprecio mucho el contenido, el trabajo y el tiempo que ponéis en vuestros artículos. Buscando en por hay he encontrado tu web. Ya he disfrutado de varios publicaciones, pero este es muy interesante, es unos de mis temas predilectos, y por su calidad me ha distraído mucho. He puesto tu blog en mis favoritos pues creo que todos tus artículos son interesantes y seguro que voy a pasar muy buenos momentos leyendolos.

  21. קוקסינליות בתל אביב

    The subsequent time I read a weblog, I hope that it doesnt disappoint me as a lot as this one. I mean, I know it was my option to read, but I truly thought youd have something attention-grabbing to say. All I hear is a bunch of whining about something that you possibly can repair should you werent too busy on the lookout for attention.

  22. Charlie Brakhage

    I have read a few of the short articles on your website now, and I really like your style of blogging. I added it to my favorites blog site list and will be checking back quickly. Please have a look at my site too and let me understand what you believe.


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