Implement Workers throttling
Categories
(Core :: DOM: Workers, enhancement)
Tracking
()
People
(Reporter: aiunusov, Assigned: aiunusov)
References
(Blocks 1 open bug)
Details
Attachments
(1 obsolete file)
Assuming that Workers are already marked running in backgroud in 1817981, implement throttling for dedicated service workers case.
Ensure that scheduling timers SetTimeout SetInterval are running no more often than every 1000ms.
Exception: when tab is playing audio.
Worker code scheduling timers: https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/dom/workers/WorkerPrivate.cpp#4944
running timers:
https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/dom/workers/WorkerPrivate.cpp#5050
Areas of the code that could help during implementing
Worker code scheduling timers: https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/dom/workers/WorkerPrivate.cpp#4944 and running timers https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/dom/workers/WorkerPrivate.cpp#5050
Workers are already suspended when Window/Document enters bfcache https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/dom/base/nsGlobalWindowInner.cpp#5717,5757 so perhaps a similar mechanism could be used to propagate information about the worker being in the background
Throttling settings: https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/modules/libpref/init/StaticPrefList.yaml#3111-3121
Main Thread timeout manager: https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/dom/base/TimeoutManager.cpp#194
https://bugzilla.mozilla.org/show_bug.cgi?id=1563335 worth checking if that code works at all anymore. It hasn’t been used at all. That would be a very different approach to the problem compared to what we do currently with background tabs.
Worker->Main thread communication already throttled(to prevent flooding): https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/dom/workers/WorkerPrivate.cpp#2484-2487
https://searchfox.org/mozilla-central/source/docshell/base/BrowsingContextGroup.cpp#113
SchedulerAPI uses the same mechanism and also AbortSignal.timeout, so those are handled automatically
Currently Window/Document objects are marked as being in background when needed, but the information isn’t propagated to the workers: https://searchfox.org/mozilla-central/rev/5ccb73c0217d1710b10d6e6e297cf3396d10ec23/dom/base/nsGlobalWindowInner.cpp#5977,5981
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 1•1 year ago
|
||
Updated•1 year ago
|
Description
•