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

    Thanks for assisting individuals receive the relevant information they need. Fantastic things customarily. Keep up the great work!

  2. Camellia Bado

    I like seeing internet sites that comprehend the value from providing a premium information free of charge. That is the aged what walks around comes around schedule.

  3. Mohamed Minks

    Thanks for discussing this appealing blog with us.My satisfaction to become right here on your blog post. I wan na come beck listed below for new message off your site.

  4. Virgilio

    in depth info you provide. It’s nice to come throughout a blog every once in a while that isn’t the very same out of date reworked info. Excellent read!

  5. belgravia villas

    Excellent blog here! Additionally your website loads up fast! What host are you the use of? Can I get your associate link in your host? I want my website loaded up as fast as yours lol

  6. p30306

    Thanks for some other fantastic article. Where else may just anybody get that type of info in such a perfect manner of writing?
    I’ve a presentation subsequent week, and I am on the search for such info.p30306

  7. Norberto Massay

    I just recently discovered several beneficial details in your website especially this blog post web page. One of the lots of discuss your articles. Thanks for discussing.

  8. Livia

    Any health-related situation could eventually turn into high priced as well as that’s bound to quickly put a monetary impediment around the family finances. Putting in squeeze exceptional travel cover offer you before leaving will be definitely worth the time and effort. Thanks

  9. 81

    Excellent blog! Do you have any tips and hints for aspiring writers?

    I’m planning to start my own blog soon but I’m a
    little lost on everything. Would you recommend starting with a free platform
    like WordPress or go for a paid option? There are so many choices out there that I’m totally confused ..
    Any tips? Thanks a lot!81

  10. historia electrodomesticos chilectra enel

    Estas mismas fuentes preven que serán en torno a 4.000 personas de CCOO y 2.000 de UGT las que a lo largo de la jornada tratarán que la huelga sea un éxito, especialmente en las primeras horas coincidiendo con el inicio del funcionamiento de los transportes la apertura de los comercios. La sesión de control de este jueves se ha desarrollado sin la presencia del presidente del Gobierno, Mariano Rajoy, que está volviendo a España después del viaje oficial que ha realizado a Seúl. El segundo gran episodio que demostró la falta de firmeza fue el pensionazo: cuatro meses después de la huelga general del 29 de septiembre, dispusieron, junto al gobierno, que tendremos que trabajar dos años más para cobrar una pensión más exigua.

  11. Link Alternatif Togel Online

    Have you ever considered publishing an ebook or guest authoring on other websites?
    I have a blog based upon on the same ideas you discuss and would love to have you share
    some stories/information. I know my subscribers would appreciate your work.
    If you’re even remotely interested, feel free to shoot me an e-mail.

  12. Searchwell

    Well together with your agreement let me to grab the Feed and keep kept up to date together with forthcoming write-up. Appreciate it a thousand along with please keep up this rewarding perform.

  13. Ervin Finlay

    Автор, ты на самом деле классный.
    Я и раньше очень любил
    читать посты на разных интернет-блогах;) Но
    невозможно было отыскать человека, взгляды которого в данном отношении
    были бы схожи с моими:)

  14. răng hô

    Niềng răng mắc cài kim loại là phương pháp chỉnh dùng
    mắc cài và dây cung đưa răng về đúng vị trí trên cung hàm, đảm bảo khớp cắn và vấn đề thẩm mỹ.

    Có 3 loại niềng răng mắc cài kim loại là Niềng răng mắc cài kim loại thường
    ngày, Niềng răng mắc cài kim loại tự khóa và niềng răng mắc cài kim loại mặt trong.

    Niềng răng mắc cài kim loại dù là mắc cài thường ngày hay mắc cài tự khóa đều có thể áp
    dụng cho tất cả các đối tượng khách hàng.
    Những trường hợp bị các khiếm khuyết về răng như hô, móm, thưa,
    lệch lạc dù là trẻ nhỏ hay người lớn đều có thể sử dụng niềng răng mắc cài kim loại.

  15. Laweta Warszawa

    Can I just say what a aid to search out somebody who truly is aware of what theyre speaking about on the internet. You definitely know how to convey an issue to mild and make it important. More people must learn this and perceive this facet of the story. I cant imagine youre not more popular because you definitely have the gift.

  16. погрузчик бобкэт

    Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across. It extremely helps make reading your blog significantly easier.

  17. Merilyn Few

    This blog is definitely rather handy since I’m at the moment creating an internet floral website – although I am only starting out therefore it’s really fairly small, nothing like this site. Can link to a few of the posts here as they are quite. Thanks much. Zoey Olsen

  18. thuoc uong

    sẹo rỗ là một loại sẹo nhiều ở nhiều
    người, tuy nhiền không phải ai cũng biết cách điều trị sẹo rỗ hiệu quả nhất, an toàn nhất.

    Ngày nay sẹo rỗ tuy không gây ra nguy hiểm hay ảnh hưởng đến tình trạng sức khỏe nhưng nó làm mất đi tính thẩm mỹ trên làn da,
    khiến nhiều người e ngại, không tự tin khi giao tiếp.

  19. Kendall Bigham

    Надеюсь, что приведенная здесь информация по-настоящему достоверна:) Я уверен, что ваш
    интернет-портал заслуживает гораздо
    больше внимания:) Конечно, я вернусь назад, и продолжу его изучение…

  20. Billy Niall

    Доброго времени суток;)
    Интересный интернет-блог… Но у меня возникают определенные проблемы с его загрузкой в браузере:
    ) Я уверен, что с этим затруднением
    сталкивается большинство
    пользователей… Будьте любезны, решите этот
    вопрос в ближайшее время!

  21. казино шампанское бонус

    Действительно полезныйвеб ресурс!
    Прошу, подскажите, дизайн вашего блога выполнен на
    заказ, или загружен откуда-то?
    Такое решение, с несколькими
    простейшими изменениями, на самом деле повысит посещаемость моего онлайн портала…
    Плиз, ответьте на мой вопрос:) С благодарностью!

  22. healthy

    sẹo rỗ là một loại sẹo nhiều ở nhiều người, tuy nhiền không phải ai cũng biết cách điều trị sẹo rỗ hiệu quả nhất, an toàn nhất.

    Ngày nay sẹo rỗ tuy không gây ra nguy hiểm hay ảnh hưởng đến tình trạng sức
    khỏe nhưng nó làm mất đi tính thẩm mỹ trên làn da, khiến nhiều người
    e ngại, không tự tin khi giao tiếp.

  23. Ohmie

    I will be really loving this theme/design of this web page. Ever come across just about any internet browser compatibility troubles?

  24. mokhche

    I feel this is among the most significant information for me. And i am glad reading your article. But should observation on few general things, The website taste is wonderful, the articles is actually excellent : D. Good job, cheers

  25. wdal sie w polemike

    I together with my pals ended up going through the good guidelines on your web blog then instantly I got a horrible feeling I had not expressed respect to the web site owner for those tips. My men happened to be certainly stimulated to learn all of them and already have simply been loving those things. Appreciation for being so considerate and for figuring out varieties of helpful topics millions of individuals are really wanting to know about. Our honest apologies for not saying thanks to you earlier.

  26. catalogo tubos estructurales de acero

    Le hará un descuento del desplazamiento cuando se lleve a cabo la reparación.Si decide no hacer la reparación de su nevera ya que puede que no tenga solución la reparación, entonces el técnico le ofrecería otro electrodoméstico de igual mayor calidad con un significativo descuento, y en otro caso solo se cobraría el desplazamiento a su domicilio, quedando siempre pendiente que si nos vuelve a llamar se le descuenta dicho desplazamiento.

Comments are closed.