wingolog

generators in firefox now twenty-two times faster

14 November 2014 8:41 AM (spidermonkey | firefox | mozilla | javascript | es6 | ecmascript | v8 | jandem | bloomberg | igalia)

It's with great pleasure that I can announce that, thanks to Mozilla's Jan de Mooij, the new ES6 generator functions are twenty-two times faster in Firefox!

Some back-story, for the unawares. There's a new version of JavaScript coming, ECMAScript 6 (ES6). Among the new features that ES6 brings are generator functions: functions that can suspend. Firefox's JavaScript engine, SpiderMonkey, has had support for generators for many years, long before other engines. This support was upgraded to the new ES6 standard last year, thanks to sponsorship from Bloomberg, and was shipped out to users in Firefox 26.

The generators implementation in Firefox 26 was quite basic. As you probably know, modern JavaScript implementations have a number of tiered engines. In the case of SpiderMonkey there are three tiers: the interpreter, the baseline compiler, and the optimizing compiler. Code begins execution in the interpreter, which is the quickest engine to start. If a piece of code is hot -- meaning that lots of time is being spent there -- then it will "tier up" to the next level, where it is analyzed, possibly optimized, and then compiled to machine code.

Unfortunately, generators in SpiderMonkey have always been stuck at the lowest tier, the interpreter. This is because of SpiderMonkey's choice of implementation strategy for generators. Generators were implemented as "floating interpreter stack frames": heap-allocated objects whose shape was exactly the same as a stack frame in the interpreter. This had the advantage of being fairly cheap to implement in the beginning, but ultimately it made them unable to take advantage of JIT compilation, as JIT code runs on its own stack which has a different layout. The previous strategy also relied on trampolining through a helper written in C++ to resume generators, which killed optimization opportunities.

The solution was to represent suspended generator objects as snapshots of the state of a stack frame, instead of as stack frames themselves. In order for this to be efficient, last year we did a number of block scope optimizations to try and reduce the amount of state that a generator frame would have to restore. Finally, around March of this year we were at the point where we could refactor the interpreter to implement generators on the normal interpreter stack, with normal interpreter bytecodes, with the vision of being able to JIT-compile those bytecodes.

I ran out of time before I could land that patchset; although the patches were where we wanted to go, they actually caused generators to be even slower and so they languished in Bugzilla for a few more months. Sad monkey. It was with delight, then, that a month or so ago I saw that SpiderMonkey JIT maintainer Jan de Mooij was interested in picking up the patches. Since then he has been hacking off and on at getting my old patches into shape, and ended up applying them all.

He went further, optimizing stack frames to not reserve space for "aliased" locals (locals allocated on the scope chain), speeding up object literal creation in the baseline compiler and finally has implemented baseline JIT compilation for generators.

So, after all of that perf nargery, what's the upshot? Twenty-two times faster! In this microbenchmark:

function *g(n) {
    for (var i=0; i<n; i++)
        yield i;
}
function f() {
    var t = new Date();
    var it = g(1000000);
    for (var i=0; i<1000000; i++)
	it.next();
    print(new Date() - t);
}
f();

Before, it took SpiderMonkey 980 milliseconds to complete on Jan's machine. After? Only 43! It's actually marginally faster than V8 at this point, which has (temporarily, I think) regressed to 45 milliseconds on this test. Anyway. Competition is great and as a committer to both projects I find it very satisfactory to have good implementations on both sides.

As in V8, in SpiderMonkey generators cannot yet reach the highest tier of optimization. I'm somewhat skeptical that it's necessary, too, as you expect generators to suspend fairly frequently. That said, a yield point in a generator is, from the perspective of the optimizing compiler, not much different from a call site, in that it causes all locals to be saved. The difference is that locals may have unboxed representations, so we would have to box those values when saving the generator state, and unbox on restore.

Thanks to Bloomberg for funding the initial work, and big, big thanks to Mozilla's Jan de Mooij for picking up where we left off. Happy hacking with generators!

119 responses

  1. Matthias says:

    This count for which Version(s) please ?

  2. Tom Schuster says:

    Wingo, thank you for taking the time to write this blog post!
    @Mathias If you look at https://bugzilla.mozilla.org/show_bug.cgi?id=1093573 you will see a "Target Milestone" of mozilla36, which is Firefox 36, or at this time Firefox nightly.

  3. Arne Babenhauserheide says:

    Congratulations! This is awesome!

    And it’s great to see that your work paid off!

    For the speed, I got this link: http://arewefastyet.com/

  4. paul says:

    Nice! Will there be real coroutines at some point? That would allow getting rid of the horrid callback nonsense in node.js.

  5. db48x says:

    Paul: Yes, you can use yield to eliminate callbacks. Rather than explain, I'll just show an example: http://db48x.net/yield/yield.js

  6. ElectricPrism says:

    Had to say, kickass work bro.

  7. William ML Leslie says:

    Hey Andy,

    Just wanted to let you know that your less-than sign in the code block seems not to be escaped in the RSS feed.

  8. half girlfriend full movie says:

    Hey Andy,

    Just wanted to let you know that your less-than sign in the code block seems not to be escaped in the RSS feed.

  9. Apparao says:

    Hey Andy,

    Good Job Brother.Keep Going.

  10. Spicy Hunting says:

    Spicy Hunting is basic factor for hunting and you will learn how you can learn more and more about hunting and cooking.

  11. bigo beans says:

    Spicy Hunting is basic factor for hunting and you will learn how you can learn more and more about hunting and cooking.

  12. Golf Rangefinder says:

    Range finding is a art which is specially for those who love to see too far from them and analysis the beauty of the environment and have a great view about the nature.

  13. SB game hacker says:

    art which is specially for those who love to see too far from them and analysis the beauty of the environment and have a great view about th

  14. Bolo says:

    A bread making machine or bread maker is a home appliance for baking bread. You will love to buy them from us and get to know best bread making machine for your home.

  15. happy mothers day says:

    Before, it took SpiderMonkey 980 milliseconds to complete on Jan's machine. After? Only 43! It's actually marginally faster than V8 at this point, which has (temporarily, I think) regressed to 45 milliseconds on this test. Anyway. Competition is great and as a committer to both projects I find it very satisfactory to have good implementations on both sides.

  16. fang james says:

    Skin Novela has a promising future. Maybe I shouldn't put it that way. You can increase the time you spend once your Skin Care gets tuned up. To set yourself free from the crowd you want to hook up with Beauty. This is why you should absolutely get Wrinkles. I only do the basics.
    Read More: http://www.suxorfree.com/skin-novela/

  17. best cat litter for odor control says:

    Anyway. Competition is great and as a committer to both projects I find it very satisfactory to have good implementations on both sides.

  18. Call Girls in Jaipur says:

    Haute young ladies of Jaipur adopt a high class strategy to models escorts in Jaipur. We don't offer anything not as much as the most first class escorting administration inside Jaipur

  19. 9appscrack says:

    Flashlight instantly turns your device into a bright torch.A reliable source of emergency light. This app takes advantage of flash of your phone and turns your device into a torch as on $100 tactical torch comes with flashing strobe which attract the attention of other people to you.Great light at your fingertips. Ready and available for any situation or emergency. And its totally free.
    https://9appscrack.com/flashlight-fastest-led-light-torch-apk/

  20. happy raksha bandhan images says:

    Nice Flashlight instantly turns your device into a bright torch.A reliable source of emergency light. This app takes advantage of flash of your phone and turns your device into a torch as on $100 tactical torch comes with flashing strobe which attract the attention of other people to you.Great light at your fingertips. Ready and available for any situation or emergency. And its totally free.

  21. Score Hero Mod Apk says:

    That's really helpful
    It would be really great if you can keep posting such great content

  22. Happy Diwali 2017 SMS says:

    Awesome piece of content that is. It is really helpful and would really great if you keep posting such more stuff here.

  23. HP 6700 Drivers says:

    this is one of the best contents I have ever seen

  24. Click the Buy Coursework Link says:

    The outcomes of further research say there are indications of breaking point dissents in the skull. The contention was not a weapon, yet rather because of an amazing hail fell on his head. They couldn't escape being gotten in the midst of the valley. The pile of ice in the valley that over the long haul transformed into the lake that spared a few skulls.

  25. Hindimeresult says:

    The outcomes of further research say there are indications of breaking point dissents in the skull. The contention was not a weapon, yet rather because of an amazing hail fell on his head. They couldn't escape being gotten in the midst of the valley.

  26. Activate Bot Comments says:

    Awesome piece of content thisbis. Just love it. Awesome it is with great things.

  27. bhatu says:

    OK

  28. happy raksha bandhan images 2017 says:

    wow nice

  29. ejeta robinson says:

    Commbank Login – CommonWealth Bank | Online Banking Commonwealth bank also known as commbank or CBA is an Australian bank that offers financial services such as insurance, institutional bank, business banking, retail banking, management of funds etc.
    https://www.tecteem.com/index.php/2017/07/23/commbank-login-common-wealth-bank-online-banking/

  30. HP Wifi Drivers says:

    This is fantastico stupendouso websito

  31. mcxgoldtips says:

    Don't blow off another's candle for it won't make yours shine brighter.

  32. crudeoiltips says:

    I have no taste for either poverty or honest labor, so writing is the only recourse left for me.

  33. QuickBooks Toll Free Number | QuickBooks Helpline Number says:

    QuickBooks Customer Service works to assist the users of accounting software. It seems that many times, the users of QuickBooks encounter unnecessary failures and errors which stopped their work and they just didn't find a way to resolve it. It has QuickBooks Tech Support Number which has accounting experts guidance to help users. It also has the assistance which works for cloud-based software or QuickBooks Online Support, the user can communicate with them at anytime and from anyplace.

  34. Ryan Smith says:

    Here is the to browers and file managers for windows [url=http://techblogideas.com]File Managers for windows[/url]
    Visit this website for more info and earn money tricks.

  35. Freaked says:

    Looking for the perfect costume that's funny and relevant? We've picked out the best outfits that will prove you don't live under a rock. https://freaked.com/halloween-costume-ideas/

  36. coc lover says:

    http://clashroyaleunlimitedhacks.blogspot.com
    http://downloadgtavtorrent.blogspot.com
    https://clashroyalemodshack.wordpress.com/
    http://clashroyalelovers.blogspot.com
    https://clashofclanslovers.weebly.com/
    http://minimilitiamodsapk.weebly.com/
    http://latestmodsapk.blogspot.com
    http://downloadmodhacks.blogspot.com
    http://modsandapk.weebly.com/
    http://modestapk.blogspot.com
    http://minimilitiamodsapks.blogspot.com
    http://minimilitiahacksapk.blogspot.com
    http://minimilitiaallinonemod.blogspot.com

  37. Today Match Prediction says:

    When you are good to go to begin cricket reproducing, it is critical to know how you should oversee and deal with your way of life. Purchasing plastic holders and a nutritious nourishment hotspot for the crickets is just not adequate. Your whole procedure of rearing should be observed deliberately with the goal that you accomplish the coveted advantages.

  38. Pyeongchang says:

    Comprensión general de Corea! Cerca de 10 gran cantidad de turistas extranjeros visitan anualmente Corea del Sur, un país lleno de historia y cultura. Cualquier visitante no nativo que esté desesperado por ingresar a la República de Corea necesita un pasaporte válido y convertirse en la visa correspondiente antes de ingresar a los EE. UU., Excepto los extranjeros que pertenecen a los países registrados con el Contrato legal de exención de visa o de estados o territorios dentro de los Principios de Reciprocidad e incluso Interés Nacional, que pueden permanecer en el Reino Unido sin visa por un tiempo determinado ...

  39. nøglering med tryk says:

    For at forbedre en bestemt forretningsstil er det tilrådeligt at tænke i forbindelse med bestemte reklame- og markedsføringsstrategier, der kan slå elementet væk under brug af offentligheden. En fremragende markedsføringsstrategi er normalt at give tilgængelige visse freebies, der indeholder dit firma på dem, der skal tænkes om nemt.

  40. Vijay Gajra says:

    Vijay seems to have 17 numerous years of manufacture experience not to mention his diversified expertise comprises of commercial ventures and house builds, and also malls, bungalows, not to mention township ventures. With your partner's first-hand practical knowledge, Vijay will be able bring a significant balance from professionalism not to mention exceptional support to your partner's position for the reason that Chairman.

  41. valentines day images 2018 says:

    Comprensión general de Corea! Cerca de 10 gran cantidad de turistas extranjeros visitan anualmente Corea del Sur, un país lleno de historia y cultura. Cualquier visitante no nativo que esté desesperado por ingresar a la República de Corea necesita un pasaporte válido y convertirse en la visa correspondiente antes de ingresar a los EE. UU., Excepto los extranjeros que pertenecen a los países registrados con el Contrato legal de exención de visa o de estados o territorios dentro de los Principios de Reciprocidad e incluso Interés Nacional, que pueden permanecer en el Reino Unido sin visa por un tiempo determinado ...

  42. Republic Day Speech says:

    Awesome

  43. Macbook Repair in Seattle says:

    David is an expert in repair MacBook in Seattle. he has excellent knowledge of repair any types of problem like screen problem, retina problem, keyboard problem and etc.

  44. Metaphysical Wholesale and New Age Supplies says:

    Indian Agate leading Manufacturer, Exporter and Supplier of Quality Metaphysical in Wholesale in India. We are dealing with Worldwide as per customer order and requirements.

  45. Website Design and Development Company in Ahmedabad says:

    Sirmedia.in Leading one of the best company in Ahmedabad which offer Website Design and Development. We make fully dynamic and mobile site according to new google updates.

  46. Pascuas Saludos says:

    El Domingo de Pascua, millones de nosotros nos estaremos metiendo en deliciosos huevos de chocolate, como lo celebra el mundo cristiano.

  47. pubg boost says:

    You may think plus read considerably about joining your niche members. The idea that you have to do its an definite. However, exactly how you would accomplish that will be easier in theory sometimes.

  48. chiro laval says:

    Are you currently following an agenda for the personal cleanliness, or would you get up each morning, take the bath, brush as well as blow dry hair, use the potty through your day, and retire for the night at evening? If you simply do the actual latter, you have to put much more planning as well as preparation into your individual care as well as grooming.

  49. Bypass Surveys says:

    Something nice to read on such a booring day.

  50. sofiya says:

    the article of self cleanliness is a great topic!

  51. Ethereum Mining Contract says:

    I love the way you wrote this article and everything in this is just amazing. I almost forgot that you should try to put more quotes in the article also. None the less everything is crystal clear, amazing work. A salute from My Ethereum News

  52. double swags says:

    The experience Kings Swag range is a high quality, low cost take on a great Aussie tradition. Designed with years of experience on the tracks and a wealth of knowledge about what works in real life situations the whole range is built from hard wearing rip stop poly cotton canvas, with reinforced waterproof PVC bucket flooring to withstand the punishment a swag endures even sharp rocky campsites, and from stands and companies in rose bush locations.

  53. best portable washing machine says:

    Good Job.

  54. pos software Company Dubai says:

    I would like to share about the a software such as pos. pos is a point of sale software used for the business development. The financial transaction done by using it.

  55. lol account says:

    This is a quick manual to Category of Stories (LoL) accounts creation. League associated with Legends is definitely an awesome MOBA online game available on the internet. It is liberated to play as well as I guarantee that you'll be hooked as soon as you check it out.

  56. Professional Essay Writing Service UK says:

    You may ponder joining your specialty individuals. The possibility that you need to do it's an unmistakable. Be that as it may, precisely how you would achieve that will be less demanding in principle in some cases.

  57. Best Wifi Names says:

    This is one of the best articles I have come across. Keep up the good work.

  58. tanishadsouza says:

    Vandexafil Ultra is FDA approved clinically formulated male enhancement supplement that includes all botanical extracts and works to lift the sexual appetite among male group and give them longer and satisfied nights without any side effects.
    http://www.wellness786.com/vandexafil-ultra/

  59. KrogerFeedback says:

    Krogerfeedback is an overview site where they give free coupons and focuses in return of criticism.
    Essentially they ask these audits since they can utilize the date which you are topping off to extemporize their administration.KrogerFeedback

  60. Eliteboost says:

    Cheap and reliable site that deals with boosting most of todays most popular games .

  61. Elisa Watson says:

    Thanks for the article. This is one of the best articles I have come across. Keep up the good work.

  62. eloboosting says:

    You gave a very nice explanation in this article

  63. KUNAL says:

    http://mcxcommoditycalls.com/

  64. http://www.kiss-top.info/ says:

    thank you so much.

  65. http://www.mm5366.com/ says:

    Thanks you so much.

  66. http://www.meimei-av.info/ says:

    Thank you so much.

  67. Mandeep kumar says:

    You gave a very nice explanation in this article

  68. happythanksgivingimage.info says:

    nice

  69. hanukkah coloring pages says:

    Your website and blogs are just fabulous, it is very good with precise content. Everyone should visit this website once for

    quality content and images. All the best !! keep up the good work.CHEERS....

  70. WiFi Names says:

    Great post thanks for posting.

  71. Prince says:

    Your website and blogs are just fabulous, it is very good with precise content. Everyone should visit this website on

  72. metdental says:

    fdgfd gdfg dfgdfg dfg

  73. kpsc thulasi says:

    f sdfsfs d fsdfsdf sd fsdf dsf dsf sdfs

  74. kpsc thulasi says:

    as dasd as faf dasfasdf af asdas dasd as das

  75. myfedloan says:

    asdasdas asfdsfsdfsdf sdfsdf sdfdsf sfs dsdfsdf

  76. mohela login says:

    adsf dfdf sdfsd fsd fdsf sdf sdf sd fdsfsd fdsf ds

  77. pscwb says:

    dsf sdfs dfds fsdf dsf dsf sdf dsfds fsdf dsf dsf

  78. anyror says:

    anyror ds sfs dfd sf sdfsd

  79. Wifi Names says:

    Thanks for such an informational guide article. :)

  80. Dandy says:

    Generators in firefox is now twenty two times even more faster

  81. Nda admit card says:

    WOW

  82. Real Ghost Stories says:

    At Strangilla, we work on real strange matters. All the unknown, weird, mysterious phenomenons are gathered from real world. The scary, paranormal and alien activies are written so well by our authors that you may feel chill to the spine.

  83. Best Instagram Captions says:

    Thanks For This Awesome Article!

  84. Dog Sites says:

    Such an awesome article this one is! It will surely help me. :)

  85. Mohela login says:

    Thanks for the great article. On of the best article shared.

  86. Law Assignment Help UK says:

    Really like your article, it is so informative.Your website and blogs are just amazing, it is very good with precise content.

  87. Kathy Kaul says:

    I absolutely Love it! Thank you for sharing it on the web!

  88. Online Law Writing Help UK says:

    Thanks for such an informational guide article. :)

  89. DLIFE Home Interiors says:

    Thanks

  90. All event download event page says:

    Great article. Keep up guys to provide valuable content.

  91. Buy Dissertation UK says:

    TheDissertationWriters is the platform with all academic writing solution in the UK, we are one of the top dissertation writers providing quality dissertation research writing covering all subjects. We have specialised writers team to deal dissertations subject wise just to provide student perfect dissertation with compromising quality.

  92. suresh pawar says:

    It is truly a nice and useful piece of info. I am glad that you just
    shared this useful information with us. Please stay
    us up to date like this. Thanks for sharing.

  93. 100 Accurate Commodity Tips says:

    nice update

  94. vishal singh says:

    nice article

  95. yoyo says:

    at the nice think

  96. kashmir online store says:

    latest post here

  97. vape shop online says:

    what the hell?

  98. Funny Wifi Names says:

    Nice Post. Thank you.

  99. Ludo Game says:

    Ludo is a perfect timepass of ludo dice game, you played ludo in childhood now you can play on phone or tablet

  100. https://mlpfriendshipismagic.webs.com says:

    Nice Post. Thank you.

  101. Sushant Travels says:

    Sushant Travels is one of the best and top tour and travels agency in Delhi, India. At Sushant Travels We are offering affordable packages for all India tour and International Tour.

  102. DC PARTY BUS SERVICE says:

    very nice post i like it

  103. Alps Ppl says:

    Nice article.Thank you...

  104. Best Wifi Names says:

    Hi,

    This post seems awesome, Yes I agree, JavaScript has developed a lot and we have been using now probably the best version of Javascript. The adaptation of new technology has amazed us a lot and we are now able to deliver a lot through the new age of javascript programming. All the features are really cool and the outcome process is the best in all aspects.

    The technology which is being used at this moment can deliver a lot. The websites and blogs we are making needs a lot of functionality and Javascript can help in it.

    New bloggers have been coming up with different blogging ideas like Instagram captions, love status, funny quotes, happy birthday quotes, best wifi names , and they need blog templates having so many functionalities and features and only new versions of javascript can deliver a unique and cool template.

  105. elma smit says:

    Thanks for the post if you want to see biography of the post then you can visit full wiki bio now utkarsh sharma

  106. Best Wifi names says:

    Thanks for sharing some nice information about it. Funny Wifi Names It really help me a lot.

  107. A Blog To Health says:

    Great job for publishing such a nice article. Your article isn’t only useful but it is additionally really informative. Thank you because you have been willing to share information with us. Crazy Mass Reviews

  108. Kathy Kaul says:

    Great Job for publishing such a nice article.Tired of living

  109. https://staircarpets.home.blog says:

    Add a minimum of 10cm 4 inches to the total length to allow for any waste. If you want a certain style https://staircarpets.home.blog and color to match your dcor then you might need to order your carpet from a carpet sample at a retail store.

  110. Love status says:

    Hi, thanks for the information provided by you. It really helped me.

    Thanks bro

  111. school science experiments says:

    Great Article !
    Thanks for sharing this amazing post it is very useful have been looking for similar topic until I come across it on your website. I will be looking forward to get more from you.

    You can also visit our website for new science projects. How To Make Boat

  112. Rocking babe says:

    Nice post thank you.

  113. Ufone Packages Call says:

    Very interesting, good job and thanks for sharing such a good blog

  114. fnaf world says:

    Information about firefox generators now twenty times faster will help to increase power output.

  115. Jeevan says:

    Thanks for your personal marvelous posting! I definitely enjoyed reading it

  116. Best Gym in alpha 1 Greater Noida says:

    Its very good article sir keep it up

  117. Girl Whatsapp Group Link says:

    Thank you very much sir its very good content

  118. Hallannd says:

    I really love this info, Its really a helpful one indeed. Thanks alot

  119. Muhammad Adil Chaudhry says:

    Thanks for sharing this amazing post it is very useful to have been looking for a similar topic until I come across it on your website. I will be looking forward to getting more from you.
    Also check a list of 2500+ best wifi names funny for your network router SSID.

Leave a Reply