Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unloading of workers (and hence Platform Collector) #104

Closed
kenchris opened this issue May 3, 2022 · 5 comments · Fixed by #105
Closed

Unloading of workers (and hence Platform Collector) #104

kenchris opened this issue May 3, 2022 · 5 comments · Fixed by #105

Comments

@kenchris
Copy link
Contributor

kenchris commented May 3, 2022

Find the right hooks to make sure we inform the platform collector when workers are unloaded

@kenchris
Copy link
Contributor Author

kenchris commented May 3, 2022

Potentially relevant:

https://html.spec.whatwg.org/#suspendable-worker
https://html.spec.whatwg.org/#dom-workerglobalscope-closing

Closing orphan workers: Start monitoring the worker such that no sooner than it stops being a protected worker, and no later than it stops being a permissible worker, worker global scope's closing flag is set to true.

Suspending workers: Start monitoring the worker, such that whenever worker global scope's closing flag is false and the worker is a suspendable worker, the user agent suspends execution of script in that worker until such time as either the closing flag switches to true or the worker stops being a suspendable worker.

Once the WorkerGlobalScope's closing flag is set to true, the event loop's task queues must discard any further tasks that would be added to them (tasks already on the queue are unaffected except where otherwise specified). Effectively, once the closing flag is true, timers stop firing, notifications for all pending background operations are dropped, etc.

@kenchris
Copy link
Contributor Author

kenchris commented May 3, 2022

This reminds me that the closing and unloading of the worker should be handled by garbage collection as we do in Generic Sensors:

When a Sensor object whose [[state]] is "activated" or "activating" is garbage collected, the user agent must invoke deactivate a sensor object with this object as argument.

@kenchris
Copy link
Contributor Author

kenchris commented May 3, 2022

We probably want to handle suspension (bfcache, suspendable worker, non-fully active document).

@rakuco does Generic Sensors handle that? It seems to only send events to active documents (why not fully active?) so I assume that you still keep the platform sensors active while in bfcache etc

@kenchris
Copy link
Contributor Author

kenchris commented May 3, 2022

Web Bluetooth has a note about disconnecting on garbage collection:

Note: Disconnecting on garbage collection ensures that the UA doesn’t keep consuming resources on the remote device unnecessarily.

@rakuco
Copy link
Member

rakuco commented May 5, 2022

Sorry for the delay here.

@rakuco does Generic Sensors handle that? It seems to only send events to active documents (why not fully active?) so I assume that you still keep the platform sensors active while in bfcache etc

Support for the "fully active" concept is pending (see w3c/sensors#415). I believe bfcache is not a concern because sensors are stopped when the page is not visible, which is the case when a page is entering the bfcache if I recall correctly (that's the case for Screen Wake Lock in the Chromium implementation at least).

Although the spec says sensors are exposed to workers, the Blink implementation currently only exposes them to Window.

Does this help you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants