I know we've discussed this a bunch, but I believe we should throttle workers in background tabs the same way we do the main thread. A background tab shouldn't be allowed to use all my CPU/battery regardless of how it's doing so.
See issue 766068 for some extra motivation.
Blocking this on Issue 766068 so that the conversation isn't split between two bugs. Please refer to the other bug for the more general conversation about throttling high-CPU-usage JavaScript.
While I agree that we should stop background tabs from using all CPU, I believe that there are better way than throttling workers in the very same way we do throttle main thread. I'd suggest doing something aggressive when we see sustained load. Ojan, WDYT?
To get more concrete, what kind of throttling are we thinking of here? Budget-based throttling identical to timers feels like a good starting point -- I can't immediately think of a reason why we should do something different.
Re #6: It's not budget-based throttling that I'm concerned about. It's unconditional 1Hz timer alignment that worries me - I don't have hard data, but I suspect that people have real-time expectations there (e.g. MDN recommends to use postMessage to work around throttling).
I think that we could start with budget-based throttling but without forcing 1Hz alignment.
Another concern of mine is what classes of work are prevalent in workers and which of them we can throttle. I expect that the load is very different from main page (e.g. timers won't be so popular).
I'm not sure why workers *in background tabs* would have more real-time expectations. I'd prefer we stick with consistency first and old consider different things if we prove it's needed for real world content. Having to explain to authors that timers are budget throttled and 1hz except if they're in a worker where they're only budget throttled just makes for a more confusing platform with more complexity to understand IMO.
One tricky part is handling the case where the worker is in a background tab but is being used by a foreground tab. This can happen for shared workers and service workers.
Re #21: Only dedicated workers are in the scope for this intervention. Shared workers and service workers run only 1% of the tasks of dedicated workers (as measured by thread time).
Comment 1 by kbr@chromium.org
, Oct 20 2017