Search code examples
javascriptgoogle-chromefirefoxv8spidermonkey

Event loop - Infinte loop won't stop rendering pipeline in Chrome but it will on Firefox


In the following codepen the "stop earth" button initiates an infinite loop.

I was expecting that the loop will prevent the browser from initating the rendering pipieline but I was surprised to see that in Chrome the gif continues smoothly.

When testing this on Firefox the gif stops immediately.

https://codepen.io/amirnamdar-the-scripter/pen/NWPeRNY

<script> 
function stop() {
while (true);
}
</script>

<body>
    <h1> Think you can stop the earth from spinning? </h1>
    <h2>Hit the button</h2>

    <button onclick="stop()" > stop earth </button>
    <img src="https://media.giphy.com/media/ux6AQI6MBwGqY/giphy.gif" width="480" height="270">
</body>

I assume that this might have something to do with the different implementations of the event loop in the different engines.

I'm curious about what V8 does differently than SpiderMonkey that results in this difference.

Thanks


Solution

  • Following Jeff's comment below I'd like to conclude the question with his answer:

    they moved gif frame rendering to the compositor thread