Tab throttling and more performance improvements in Chrome M87
blog.chromium.org
blog.chromium.org
It claims that it still ticks timers once a minute for background tabs, but I can measure that it ticks exactly zero times for background tabs (and from now on also for foreground tabs that are occluded...), and in addition may also lie in results of Date.now(). So what does the article even mean by "once per minute"? If I put a tab in background, it immediately stops any tick, if I bring the tab back in the foreground 24 real life hours later, it'll have been 24 real life hours since its last update, not one minute, as I can see by printing events in the console.
That makes it difficult to correctly update how much resources were produced in the game, etc....
This is a very basic issues with doing stuff on a timer, and not that hard to do properly. It shouldn't make a difference if your timer is called once per second, once per minute or once in 10 hours in the background, you always calculate based on the delta to the last time your timer fired.
Doing the work in one giant update is actually better from a power consumption / battery point-of-view, because the CPU cost is fixed but there are fewer wakeups overall.
Note that the new throttling logic means you get woken-up once per minute; we're not talking about preventing your page from doing work for a 24 hour period.
For full details of how the throttling works, see here:
[1] https://developer.mozilla.org/en-US/docs/Web/API/AbortContro...
Here is some context (just a random thread about the issue, threads like this pop up regularly):
https://www.reddit.com/r/incremental_games/comments/j86u5m/g...
5 years ago such games worked in background tabs. Then browsers started throttling background tabs (for understandable reasons) and everyone learned to keep it in a foreground tab in a window you don't use. Now the latter will also stop working.
Yes, for now all workers continue to run unthrottled (shared, dedicated and service). They may also be throttled at some point, but we have no firm plans around this yet.
We don't throttle workers (that could change, but we don't have firm plans here yet).
All things being equal, if you move complex work to workers we're happy because it frees up the main thread to handle input events, compositing, etc. Just because your tab is in the background doesn't mean your renderer process isn't sharing a main thread with a tab that is in the foreground, so in this case it can improve foreground tab performance.
Also, spreading a fixed amount of work across more cores and fewer wake-ups is actually more efficient from a power point of view (assuming the wake-ups are synchronized).
Yes, lots of sites are written with tight setInterval/setTimeout loops, checking for modifications to the DOM, visibility, doing animations, etc. In most cases there are modern web APIs that do these things for you that don't require polling (rAF, MutationObserver, IntersectionObserver, etc). Throttling is mostly about reducing the impact of these sites. We are not trying to penalize well-written sites, and if you have valid use cases that you feel are being unfairly penalized we're more than happy to accept feedback!
var tid = setInterval(function() {
var bef = new Date().getTime();
debugger ;var af = new Date().getTime();
if (af - bef > 100) {
clearInterval(tid);
window.location.href = "/";
}
}, 100);Is this something people actually do? Especially on production?
https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibi...
I wonder if this would effect Web Workers in the same way.
The primary source of energy savings would be poorly written websites that constantly poll in the background. Games with complicated logic would still consume the same amount of energy.
For the most part, events can't really accumulate, because not running code means no new events are posted. The throttling applies to setTimeout/setInterval, and not to any external event (incoming network data, API callbacks, etc).
Sites that legitimately have to do a fixed amount of work per unit time (via timers) will simply do that work with 1 wake-up per minute. All things being equal, this still means less battery usage because energy usage is a function of both wakeups and total CPU usage.
> The primary source of energy savings would be poorly written websites that constantly poll in the background.
This is the key insight here, and really what we're going after. There is a lot of this on the web.