WorkerRunnable/WorkerDebuggeeRunnable refactoring (eliminate cancellation and therefore ClearMainEventQueue)
Categories
(Core :: DOM: Workers, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox116 | --- | fixed |
People
(Reporter: edenchuang, Assigned: edenchuang)
References
(Blocks 1 open bug)
Details
Attachments
(3 files, 1 obsolete file)
This is a bug for tracking our WorkRunnable refactoring.
According to https://mozilla-hub.atlassian.net/browse/FFXP-1949, the followings are the targets for this bug.
-
Eliminate cancellation from WorkerRunnables
-
Eliminate busy count in favor of just letting workerrefs and the existence of IPC actors keep a worker alive. Simplifies worker runnable too.
-
Distinguish WorkerRunnables meant to run on the worker thread from those meant to run on the main/parent thread by having a different base class (like WorkerParentRunnable), eliminating the need to have a (still) living worker when executed
https://bugzilla.mozilla.org/show_bug.cgi?id=1799173 shows the defects of our current implementation. And Worker's lifecycle would be much simpler after this refactoring.
Assignee | ||
Updated•2 years ago
|
Updated•1 year ago
|
Assignee | ||
Comment 1•1 year ago
|
||
WorkerRunnable needs not to inherit nsICancelRunnable.
Without Cancel(),WorkerRunnable::Run() would be executed even the WorkerPrivate is getting to closing/cancling/killing to release its corresponding resource.
However, WorkerRunnable::WorkerRun() is not assured can be executed as normal during the WorkerPrivate's shutting down, WorkerRunnable::Discard() is introduced to perform the specific resource releasing work.
Comment 2•1 year ago
|
||
As part of the changes here, we should also make sure that dispatch guards are relaxed. Some of this has already been explicitly mentioned in related docs, but just for clarity:
- As discussed in https://bugzilla.mozilla.org/show_bug.cgi?id=1777921#c10 the guard about not dispatching to workers beyond Running should be relaxed to beyond Canceling. It should always be okay to dispatch a runnable to a Worker in Canceling.
- We should remove all guards about what threads are allowed to dispatch to a worker.
- We should remove all concept of wrapping runnables that aren't worker runnables (because it will no longer be necessary).
It's quite possible that we can potentially expedite work on this bug by taking the above steps and removing all calls to ClearMainEventQueue as a first step. Like, it's potentially okay for the cancel methods to be dead code for non-control-runnables, with us always running the runnables.
Assignee | ||
Comment 3•1 year ago
|
||
Updated•1 year ago
|
Assignee | ||
Comment 4•1 year ago
|
||
Depends on D173850
Updated•1 year ago
|
Assignee | ||
Comment 5•1 year ago
|
||
Some behavior for WorkerStatus is changed since removing the ClearMainEventQueue.
When entering “Closing”
- Keeping receives normal WorkerRunnables
- Cancel all timeout
- Don’t clear the main event queue anymore. But we still wait for all SyncLoops be completed.
- Switching to “Canceling” by asking parent thread to call WorkerPrivate::Cancel()
When entering “Canceling”
- Notify WorkerScope, it should start dying and stop the WebTaskScheduler
- Notify StrongWorkerRefs, worker is in “Canceling”, send and complete the corresponding shutdown work right now.
- Executing all runnables until no normal WorkerRunnables in queue and no WorkerRefs, SyncLoops and children workers
WorkerRefs could be created in this status, but it would be notified immediatly to start shutdown behavior. - Stop receiving normal WorkerRunnables and DisconnectEventTargetObjects of WorkerScope.
- Entering “Killing”
When entering “Killing”
- We would not notify WorkerRefs anymore. Logically all WorkerRefs should be released in “Canceling”
- Executing all remaining ControlRunnables
- Release corresponding resources of Worker on worker thread.
Depends on D173850
Updated•1 year ago
|
Updated•1 year ago
|
Comment 6•1 year ago
|
||
Marking as leave-open since this bug currently also is defined to include some other enhancements, in particular removing busy count. That said, it might make sense to create spin-off bugs for those and close this once those are filed.
Comment 7•1 year ago
|
||
(In reply to Andrew Sutherland [:asuth] (he/him) from comment #6)
Marking as leave-open since this bug currently also is defined to include some other enhancements, in particular removing busy count. That said, it might make sense to create spin-off bugs for those and close this once those are filed.
Yes, please create spin-off bugs, thanks.
Comment 8•1 year ago
|
||
(In reply to Jens Stutte [:jstutte] from comment #7)
Yes, please create spin-off bugs, thanks.
(In reply to Eden Chuang[:edenchuang] from comment #0)
- Eliminate busy count in favor of just letting workerrefs and the existence of IPC actors keep a worker alive. Simplifies worker runnable too.
I have filed bug 1836700 to spin this off to a follow-up.
- Distinguish WorkerRunnables meant to run on the worker thread from those meant to run on the main/parent thread by having a different base class (like WorkerParentRunnable), eliminating the need to have a (still) living worker when executed
I believe bug 1769913 makes sense to track this after bug 1836700 is addressed, since the elimination of the busy count can potentially eliminate the need to have worker-to-main-thread runnables be a special class at all. (As long as there is no syncloop involved.) I'm going to update that bug.
Pushed by echuang@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/910dabb8545d P1 Adding log for Worker. r=asuth https://hg.mozilla.org/integration/autoland/rev/32515f9b41c7 P2 remove nsICancelableRunnable inheriting form WorkerRunnable. r=asuth https://hg.mozilla.org/integration/autoland/rev/b1ab6c750d04 P3 Remove WorkerPrivate::ClearMainEventQueue() r=asuth,smaug
Comment 10•1 year ago
|
||
bugherder |
Assignee | ||
Updated•1 year ago
|
Updated•1 year ago
|
Description
•