-
Notifications
You must be signed in to change notification settings - Fork 141
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
[worklets] relationship to JavaScript agent clusters #380
Comments
I'll probably fix this as part of whatwg/html#2521. The tentative conclusion is that each worklet is its own Agent Cluster so it cannot share memory with anyone but itself. |
Note that the tentative conclusion changed due to audio worklets. They should now be part of their owner's agent cluster (while being their own agent) and #385 needs to be fixed to get it properly defined. Tentative [[CanBlock]] value is false. |
If a worklet has two globals, such as paint worklets, should those be in the same agent? I guess it technically doesn't matter, but it seems a little cleaner if they are. Is there some terminology available that gets you all of the globals? |
I'd also like to use this issue (or maybe a separate one?) as a reminder to the worklets teams to write web platform tests for the [[CanBlock]] of worklets, whatever it ends up being. We have tests for the other agents in web-platform-tests/wpt#5569 which you can emulate. |
Per WebAudio/web-audio-api#1194 (comment) it should be false, though it would be good for @padenot and @hoch to confirm. It'll primarily affect audio worklets as nobody else gets |
Define the infrastructure for SharedArrayBuffer. This also clarifies along which boundaries a browser implementation can use processes and threads. shaky foundation. Because of that, similar-origin window agents are the best place to store state that would formerly go on unit of related similar-origin browsing contexts. tc39/ecma262#882 is follow-up to define agents in more detail; in particular make their implicit realms slot explicit. w3c/css-houdini-drafts#224 is follow-up to define worklet ownership better which is needed to define how they relate to agent (sub)clusters. Fixes part of #2260. Fixes w3c/ServiceWorker#1115. Fixes most of w3c/css-houdini-drafts#380 (no tests and no nice grouping of multiple realms in a single agent as that is not needed).
Yes, it should be false for |
Confirming @padenot's comment; false for On a related note, I believe folks working AnimationWorklet project are also considering some sorts of communication channel between threads or global scopes. @bfgeek might be able to share his opinion on this. |
I don't quite understand how we would allow blocking calls from an |
So I used a broad term: "the next version of Web Audio API". Just to keep the door open for SAB in the future. |
To be clear, if we you base |
Right, I think @hoch probably meant keeping the door open for Atomics.wait/[[CanBlock]] = true in the future. |
There is no way we can ever allow |
For AudioWorklet case, I agree that it does not make sense much. Are you saying that Web Audio API (the spec in its entirety) should not ever support SAB or I know some people are seriously interested in using a worker + SAB + audio callback. Should we just tell them that it won't happen in Web Audio API ever? |
My position is that we should allow SAB in |
I completely misunderstood the issue here and I am still not sure of this question is about SAB or Atomics. @domenic told me it's about both and I don't think AudioWG had a discussion on these new terms at all. So I will defer my confirmation until we resolve this in our WG. |
I might have confused things a bit, as we meandered through this thread. Let me try to re-summarize. The agent/agent cluster formalism defines two separable things:
Atomics.wait() is governed by a boolean, [[CanBlock]]. It seems like everyone is on board with that boolean being false (so you cannot use Atomics.wait()). Thus when people say "false for AudioWorklet v1", since false is a boolean, it is easy to interpret this as being about Atomics.wait(), and unrelated to sharing memory. I'm not sure what was intended though. The question of who you can share memory with is a separate question that also needs to be resolved. It could be the case that we say for "v1" you cannot share memory with anyone. But it is a pretty easy change to allow sharing memory with the parent window, and it is entirely on the HTML side. It is basically the same issue as #385 / #224. If you say that worklets and their main thread cannot share memory ("are not in the same agent cluster"), then postMessaging SABs between them will cause messageerror events (instead of the usual message event). Another thing to note is that even if you don't allow sharing memory between the worklet and main thread, SharedArrayBuffer still "works" inside worklets. You just can't share it with anyone, so it's kind of pointless. SharedArrayBuffer is a JavaScript global like Promise or Map or Math and can't be turned off. So it seems like we are still not settled on whether worklets can share memory with the main thread. @padenot thinks they should be able to. @hoch would like to discuss in the WG. I think that is where we are now. |
In particular, agents define whether you can use Atomics.wait(), agent clusters define who you can share memory with. I had forgotten we could indeed make each worklet its own agent cluster, thereby disabling SharedArrayBuffer objects. |
Quoth @domenic:
I had a discussion with @padenot about this last night and my take on it - so far - is that worklets cannot be in the same agent cluster as the main thread because their lifetimes are insufficiently coordinated. Specifically, my understanding is that the worklet thread is simply destroyed if the document in the main thread, and its worker threads, are pushed into the window history. When that document and its workers are subsequently re-activated, they may be left hanging forever waiting for something (an update to shared memory) that will never come from the worklet, because the worklet no longer exists. On the other hand: if there is some kind of reliable and predictable infrastructure around that (eg, the main document can listen for some event that said it was deactivated and reactivated, and the liveness of the worklet can be inferred reliably from that event) then my concern in the previous paragraph may not matter. All I care about is that it should be possible to write reliable threaded code, and for that to happen, programs must know whether threads are shut down by the embedding. (But I don't know enough about the details to the web stack and worklets to make a call on that.) |
The document and its worker threads may be destroyed too when you navigate (and are in most implementations, I think only Firefox currently allows them to be revived). |
That seems like a potentially massive source of incompatibility... |
Define the infrastructure for SharedArrayBuffer. This also clarifies along which boundaries a browser implementation can use processes and threads. shaky foundation. Because of that, similar-origin window agents are the best place to store state that would formerly go on unit of related similar-origin browsing contexts. tc39/ecma262#882 is follow-up to define agents in more detail; in particular make their implicit realms slot explicit. w3c/css-houdini-drafts#224 is follow-up to define worklet ownership better which is needed to define how they relate to agent (sub)clusters. Fixes part of #2260. Fixes w3c/ServiceWorker#1115. Fixes most of w3c/css-houdini-drafts#380 (no tests and no nice grouping of multiple realms in a single agent as that is not needed).
This is the case, at least for an An A triplet of methods ( When loading up a document (either from history, or going to it from the first time), an When navigating away from a document, the Proper synchronization is easy to do, with this mechanism, so we are in the situation you describe in your second paragraph. |
OK, given that I don't see any obvious technical problems with allowing the worklet agent to be part of the agent cluster and allowing it to share memory with the other agents in the cluster. (I'm indifferent to the value of [[CanBlock]] for worklets, but it's certainly safe to start out by setting it to false. The atomic ops will remain available so safe nonblocking algorithms are possible. I'm not yet convinced they will be good, safe nonblocking algorithms since they'll have to busy-wait, but perhaps there's some other mechanism that allows them to suspend and restart.) |
Define the infrastructure for SharedArrayBuffer. This also clarifies along which boundaries a browser implementation can use processes and threads. Tests: web-platform-tests/wpt#5569. Follow-up to define similar-origin window agents upon a less shaky foundation is #2528. Because of that, similar-origin window agents are the best place to store state that would formerly go on unit of related similar-origin browsing contexts. tc39/ecma262#882 is follow-up to define agents in more detail; in particular make their implicit realms slot explicit. w3c/css-houdini-drafts#224 is follow-up to define worklet ownership better which is needed to define how they relate to agent (sub)clusters. Fixes part of #2260. Fixes #851. Fixes w3c/ServiceWorker#1115. Fixes most of w3c/css-houdini-drafts#380 (no tests and no nice grouping of multiple realms in a single agent as that is not needed).
Define the infrastructure for SharedArrayBuffer. This also clarifies along which boundaries a browser implementation can use processes and threads. Tests: web-platform-tests/wpt#5569. Follow-up to define similar-origin window agents upon a less shaky foundation is #2528. Because of that, similar-origin window agents are the best place to store state that would formerly go on unit of related similar-origin browsing contexts. Follow-up for better agent shutdown notifications: #2581. tc39/ecma262#882 is follow-up to define agents in more detail; in particular make their implicit realms slot explicit. w3c/css-houdini-drafts#224 is follow-up to define worklet ownership better which is needed to define how they relate to agent (sub)clusters. Fixes part of #2260. Fixes #851. Fixes w3c/ServiceWorker#1115. Fixes most of w3c/css-houdini-drafts#380 (no tests and no nice grouping of multiple realms in a single agent as that is not needed).
Was this ever resolved in the spec? I was investigating a Chrome bug about passing a SAB to an AudioWorklet and ended up here. :-) |
After reading through comments again, I believe the conclusion here is to add the worklet agent to be part of the agent cluster. Perhaps someone should work on a PR? |
#224 is related as well (and referenced from the HTML Standard, which would need to be updated). |
Okay. If I were to make the necessary spec change, would this be good enough?
Per the last comment in #224, the Worklet spec already has the bit about the owner document. Please advise if I am missing anything. |
What you'd need to do is:
|
Thanks for the pointer, @domenic! But I am not sure about where the first bullet point is being done in the HTML spec. (except for the list of relationships in the example box) Can you provide an example of such definition? I believe the rest seems straightforward. |
(In imprecise English, this is saying that windows and workers can share memory with dedicated workers that they own.) |
I see - I was looking for something more extensive. For Audio Worklet, an AudioWorkletGlobalScope is associated with a BaseAudioContext, which only can be owned by a window agent. (Workers can't instantiate BAC.) That leaves us:
TBH I am having trouble understanding the part (b), but I believe it roughly matches the concept of "WorkletGlobalScope" (an event loop on a thread). Also if this is an "imprecise" version of it, how do we make it more "precise"? |
That looks precise, and yeah, the (b) part is annoyingly circuitous in the existing text; I'm not sure how to make it better though. Do WorkletGlobalScopes have owner sets, which contain Document objects? If so then that definition seems perfect. But I kind of thought some of the open issues here were about defining the ownership relationship in the first place. |
I believe so. Thanks for your advice and I will try to draft a PR for it. |
I see they have owner documents. (I guess worklets can only be owned by one document, whereas because of the shared- and service-worker cases, workers can be owned by multiple.) So that should simplify us to
Because it is Friday I drew you a picture: If you squint closely enough you should be able to find:
^_^ |
Glad we're looking at the same spot in the spec. This is a great overview for me; TIL agent, realm and owner document. :) |
The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f
The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f
The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <[email protected]> Reviewed-by: Hongchan Choi <[email protected]> Reviewed-by: Hiroki Nakagawa <[email protected]> Cr-Commit-Position: refs/heads/master@{#598619}
The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <[email protected]> Reviewed-by: Hongchan Choi <[email protected]> Reviewed-by: Hiroki Nakagawa <[email protected]> Cr-Commit-Position: refs/heads/master@{#598619}
The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <[email protected]> Reviewed-by: Hongchan Choi <[email protected]> Reviewed-by: Hiroki Nakagawa <[email protected]> Cr-Commit-Position: refs/heads/master@{#598619}
…ioWorklet, a=testonly Automatic update from web-platform-testsAllow posting a SharedArrayBuffer to AudioWorklet The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <[email protected]> Reviewed-by: Hongchan Choi <[email protected]> Reviewed-by: Hiroki Nakagawa <[email protected]> Cr-Commit-Position: refs/heads/master@{#598619} -- wpt-commits: 2c89bbecfab9a69190906abd7610c3bc62303dd4 wpt-pr: 13445
…ioWorklet, a=testonly Automatic update from web-platform-testsAllow posting a SharedArrayBuffer to AudioWorklet The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <[email protected]> Reviewed-by: Hongchan Choi <[email protected]> Reviewed-by: Hiroki Nakagawa <[email protected]> Cr-Commit-Position: refs/heads/master@{#598619} -- wpt-commits: 2c89bbecfab9a69190906abd7610c3bc62303dd4 wpt-pr: 13445
The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <[email protected]> Reviewed-by: Hongchan Choi <[email protected]> Reviewed-by: Hiroki Nakagawa <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#598619}(cherry picked from commit 97167bd) Reviewed-on: https://chromium-review.googlesource.com/c/1280843 Reviewed-by: Ben Smith <[email protected]> Cr-Commit-Position: refs/branch-heads/3538@{#998} Cr-Branched-From: 79f7c91-refs/heads/master@{#587811}
Define the infrastructure for SharedArrayBuffer. This also clarifies along which boundaries a browser implementation can use processes and threads. Tests: web-platform-tests/wpt#5569. Follow-up to define similar-origin window agents upon a less shaky foundation is whatwg#2528. Because of that, similar-origin window agents are the best place to store state that would formerly go on unit of related similar-origin browsing contexts. Follow-up for better agent shutdown notifications: whatwg#2581. tc39/ecma262#882 is follow-up to define agents in more detail; in particular make their implicit realms slot explicit. w3c/css-houdini-drafts#224 is follow-up to define worklet ownership better which is needed to define how they relate to agent (sub)clusters. Fixes part of whatwg#2260. Fixes whatwg#851. Fixes w3c/ServiceWorker#1115. Fixes most of w3c/css-houdini-drafts#380 (no tests and no nice grouping of multiple realms in a single agent as that is not needed).
…ioWorklet, a=testonly Automatic update from web-platform-testsAllow posting a SharedArrayBuffer to AudioWorklet The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <binjichromium.org> Reviewed-by: Hongchan Choi <hongchanchromium.org> Reviewed-by: Hiroki Nakagawa <nhirokichromium.org> Cr-Commit-Position: refs/heads/master{#598619} -- wpt-commits: 2c89bbecfab9a69190906abd7610c3bc62303dd4 wpt-pr: 13445 UltraBlame original commit: a9f42748483700ec4e6d4f79bcc8ffef9f0b4824
…ioWorklet, a=testonly Automatic update from web-platform-testsAllow posting a SharedArrayBuffer to AudioWorklet The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <binjichromium.org> Reviewed-by: Hongchan Choi <hongchanchromium.org> Reviewed-by: Hiroki Nakagawa <nhirokichromium.org> Cr-Commit-Position: refs/heads/master{#598619} -- wpt-commits: 2c89bbecfab9a69190906abd7610c3bc62303dd4 wpt-pr: 13445 UltraBlame original commit: a9f42748483700ec4e6d4f79bcc8ffef9f0b4824
…ioWorklet, a=testonly Automatic update from web-platform-testsAllow posting a SharedArrayBuffer to AudioWorklet The HTML spec only allows passing SharedArrayBuffers to an agent in the same agent cluster. Worklets currently do not belong to any agent cluster, so a SharedArrayBuffer can not be shared with a worklet. However, it is intended that this is possible; see, for example, w3c/css-houdini-drafts#380 and the AudioWorklet article here: https://developers.google.com/web/updates/2018/06/audio-worklet-design-pattern#webaudio_powerhouse_audio_worklet_and_sharedarraybuffer This change funnels the agent cluster ID through when creating a ThreadedWorklet, so a SharedArrayBuffer can be shared as long as the creator of the Worklet's thread is in the same agent cluster. It is not clear that this is the behavior that will be specified, however. Bug: chromium:892067 Change-Id: If1a2187ae38da41f2389538c07e7b04921c6128f Reviewed-on: https://chromium-review.googlesource.com/c/1262932 Commit-Queue: Ben Smith <binjichromium.org> Reviewed-by: Hongchan Choi <hongchanchromium.org> Reviewed-by: Hiroki Nakagawa <nhirokichromium.org> Cr-Commit-Position: refs/heads/master{#598619} -- wpt-commits: 2c89bbecfab9a69190906abd7610c3bc62303dd4 wpt-pr: 13445 UltraBlame original commit: a9f42748483700ec4e6d4f79bcc8ffef9f0b4824
For the worklets that support StructuredSerialize and StructuredDeserialize, see also WebAudio/web-audio-api#1194 for the details of that, we'll need to define how worklets relate to JavaScript agent clusters. Otherwise it's unclear whether SharedArrayBuffer always fails or always succeeds.
Maybe as part of whatwg/html#2518 or a follow-up.
cc @bakulf @domenic @lars-t-hansen
The text was updated successfully, but these errors were encountered: