Open Bug 1818463 Opened 2 years ago Updated 5 months ago

Implement Workers throttling

Categories

(Core :: DOM: Workers, enhancement)

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: nobody → aiunusov
Depends on: 1897400
Depends on: 1911780
Depends on: 1917822
Depends on: 1926181
Attachment #9411492 - Attachment is obsolete: true
Depends on: 1944883
Depends on: 1945470
Depends on: 1945779
Depends on: 1945798
Blocks: 1946468
Blocks: 1774542
Depends on: 1954770
Depends on: 1959365
Depends on: 1960822
Blocks: 1965514
Depends on: 1967608
Depends on: 1971493
Blocks: 1981108
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: