-
Notifications
You must be signed in to change notification settings - Fork 169
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
Improve description of parameters for process() calls on client objects extending AudioWorkletProcessor #1933
Comments
https://drafts.css-houdini.org/css-paint-api-1/#dom-paintworkletglobalscope-registerpaint has
and uses https://heycam.github.io/webidl/#invoke-a-callback-function to invoke a paint callback. Is that what is intended here? |
The best design to support efficient implementations would allow all objects to be maintained for reuse across There are some steps in https://heycam.github.io/webidl/#invoke-a-callback-function that look useful. If using WebIDL to describe the call, then an efficient implementation means using WebIDL types that pass by reference instead of copy in the conversions. The A, perhaps
An interface with a named property getter would be a possible alternative to |
This already has been ruled out. Because we can't keep these objects from being transferred to a different thread. (We discussed it one or two years ago, but I have to look through the find the right issue.) Also freezing the input/output array also punted to the V.next. (#1515, and you already commented on it) |
With that said, the confusion between WebIDL and ECMAScript seems like an editorial issue. We'll try to address that in the next WG meeting. |
https://heycam.github.io/webidl/#invoke-a-callback-function would "perform a microtask checkpoint" in "clean up after running script", but that would be in conflict with "Any Promise resolved within the execution of process method will be queued into the microtask queue in the AudioWorkletGlobalScope" in https://webaudio.github.io/web-audio-api/#rendering-loop If we can't use "invoke a callback function", then WebIDL may not be of any benefit here and it may be simpler to describe the parameters as ECMAScript Arrays and an Object. (The |
I am a bit confused what problems we want to solve here.
All of these are quite different. @karlt Can you pinpoint and change the issue title accordingly? |
The key issue is the description of the parameters. Part of the lack of clarity comes from the mix of ECMAScript and WebIDL types. The rest is a discussion of the implications of various options here. This issue is about the Arrays and the "map" object (which contain the Float32Arrays). These do not have a buffer to detach, and they are not Transferable. https://github.com/WebAudio/web-audio-api/issues/1934 covers the Float32Arrays, whose types are clearly defined, but whose behavior is not completely described. Some of the lack of clarity has come from It appears that the consequence of Prior to the introduction of An associated comment explained #869 (comment)
I don't feel as strongly as that comment. While it is possible to describe The issue with the |
F2F resolution: Performance is important and this will lead to changes to the spec.
|
….process() parameters r=padenot,bzbarsky Objects are retained for re-use so as to reduce garbage generation and other performance benefits. This is currently unspecified. https://github.com/WebAudio/web-audio-api/issues/1934 WebAudio/web-audio-api#1933 WebAudio/web-audio-api#1935 tracks specification of zero-channels of input when inputs are not actively processing. Differential Revision: https://phabricator.services.mozilla.com/D34836 --HG-- extra : moz-landing-system : lando
https://heycam.github.io/webidl/#call-a-user-objects-operation may be a simpler option here, but there are some small optimizations possible with using JS::Call() directly: JS::ExposeObjectToActiveJS() is not necessary because parameters are PersistentRooted and so won't be gray. MaybeWrapObjectValue() is not necessary because parameters are already in the appropriate compartment. See also WebAudio/web-audio-api#1967 and WebAudio/web-audio-api#1933 Microtask support is tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1566312 Differential Revision: https://phabricator.services.mozilla.com/D34838 --HG-- extra : moz-landing-system : lando
….process() parameters r=padenot,bzbarsky Objects are retained for re-use so as to reduce garbage generation and other performance benefits. This is currently unspecified. https://github.com/WebAudio/web-audio-api/issues/1934 WebAudio/web-audio-api#1933 WebAudio/web-audio-api#1935 tracks specification of zero-channels of input when inputs are not actively processing. Differential Revision: https://phabricator.services.mozilla.com/D34836
https://heycam.github.io/webidl/#call-a-user-objects-operation may be a simpler option here, but there are some small optimizations possible with using JS::Call() directly: JS::ExposeObjectToActiveJS() is not necessary because parameters are PersistentRooted and so won't be gray. MaybeWrapObjectValue() is not necessary because parameters are already in the appropriate compartment. See also WebAudio/web-audio-api#1967 and WebAudio/web-audio-api#1933 Microtask support is tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1566312 Differential Revision: https://phabricator.services.mozilla.com/D34838
I am assigning this to @padenot because the issue came up from FireFox's AW implementation. |
F2F conclusion from TPAC 2019:
Action items:
|
….process() parameters r=padenot,bzbarsky Objects are retained for re-use so as to reduce garbage generation and other performance benefits. This is currently unspecified. https://github.com/WebAudio/web-audio-api/issues/1934 WebAudio/web-audio-api#1933 WebAudio/web-audio-api#1935 tracks specification of zero-channels of input when inputs are not actively processing. Differential Revision: https://phabricator.services.mozilla.com/D34836 UltraBlame original commit: 3cbbbf45fe77986a8fdeaa8d67fa95aded0427ab
https://heycam.github.io/webidl/#call-a-user-objects-operation may be a simpler option here, but there are some small optimizations possible with using JS::Call() directly: JS::ExposeObjectToActiveJS() is not necessary because parameters are PersistentRooted and so won't be gray. MaybeWrapObjectValue() is not necessary because parameters are already in the appropriate compartment. See also WebAudio/web-audio-api#1967 and WebAudio/web-audio-api#1933 Microtask support is tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1566312 Differential Revision: https://phabricator.services.mozilla.com/D34838 UltraBlame original commit: a87f84004aaaee793217259c741f723262230760
….process() parameters r=padenot,bzbarsky Objects are retained for re-use so as to reduce garbage generation and other performance benefits. This is currently unspecified. https://github.com/WebAudio/web-audio-api/issues/1934 WebAudio/web-audio-api#1933 WebAudio/web-audio-api#1935 tracks specification of zero-channels of input when inputs are not actively processing. Differential Revision: https://phabricator.services.mozilla.com/D34836 UltraBlame original commit: 3cbbbf45fe77986a8fdeaa8d67fa95aded0427ab
https://heycam.github.io/webidl/#call-a-user-objects-operation may be a simpler option here, but there are some small optimizations possible with using JS::Call() directly: JS::ExposeObjectToActiveJS() is not necessary because parameters are PersistentRooted and so won't be gray. MaybeWrapObjectValue() is not necessary because parameters are already in the appropriate compartment. See also WebAudio/web-audio-api#1967 and WebAudio/web-audio-api#1933 Microtask support is tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1566312 Differential Revision: https://phabricator.services.mozilla.com/D34838 UltraBlame original commit: a87f84004aaaee793217259c741f723262230760
….process() parameters r=padenot,bzbarsky Objects are retained for re-use so as to reduce garbage generation and other performance benefits. This is currently unspecified. https://github.com/WebAudio/web-audio-api/issues/1934 WebAudio/web-audio-api#1933 WebAudio/web-audio-api#1935 tracks specification of zero-channels of input when inputs are not actively processing. Differential Revision: https://phabricator.services.mozilla.com/D34836 UltraBlame original commit: 3cbbbf45fe77986a8fdeaa8d67fa95aded0427ab
Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 Bug: 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96
We missed one thing. The last argument |
Also we decided to change the length of arrays dynamically to signal the change of incoming connections or automation rate. Now I am not sure if this is a good idea because any changes in the shape of underlying arrays will cause memory allocation. All data containers are a FrozenArray or a frozen object, so there's no way to modify its content after the integrity level change. So we have to throw it away and create a new one. Checking the detached status of an array is less of an issue here, but the dynamic change of array shape leads to reallocation is a potential problem. |
Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. This is an API change [4], but the real world impact would be negligible because there's no functionality change. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 [4]: https://chromestatus.com/feature/5647541725036544 Bug: 1071085, 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96
I think a reasonable option here is to use the automation rate to gate this. If it's k -rate, then the arrays are always length 1. If it's a-rate, it's always full length even if we know a priori that the values are constant. I doubt people toggle back and forth between automation rates[1], so the array length is pretty much fixed. [1] I'm speculating here; I have no evidence one way or another. And if they do, it would be relatively infrequent. If it causes too much garbage, it's pretty easy to make it fixed and still work well. (Always a-rate and do your own checking for constant values if it matters enough to check.) |
Although that assumption is sensible, the impl still needs to prepare the corner case. Freezing an object makes this problem even worse. |
Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. [3] This is an API change [4], but the real world impact would be negligible because there's no functionality change. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 [4]: https://chromestatus.com/feature/5647541725036544 Bug: 1071085, 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96
Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. [3] This is an API change [4], but the real world impact would be negligible because there's no functionality change. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 [4]: https://chromestatus.com/feature/5647541725036544 Bug: 1071085, 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96
Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. [3] This is an API change [4], but the real world impact would be negligible because there's no functionality change. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 [4]: https://chromestatus.com/feature/5647541725036544 Bug: 1071085, 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218702 Reviewed-by: Raymond Toy <rtoy@chromium.org> Reviewed-by: Yuki Shiino <yukishiino@chromium.org> Commit-Queue: Hongchan Choi <hongchan@chromium.org> Cr-Commit-Position: refs/heads/master@{#779052}
Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. [3] This is an API change [4], but the real world impact would be negligible because there's no functionality change. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 [4]: https://chromestatus.com/feature/5647541725036544 Bug: 1071085, 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218702 Reviewed-by: Raymond Toy <rtoy@chromium.org> Reviewed-by: Yuki Shiino <yukishiino@chromium.org> Commit-Queue: Hongchan Choi <hongchan@chromium.org> Cr-Commit-Position: refs/heads/master@{#779052}
Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. [3] This is an API change [4], but the real world impact would be negligible because there's no functionality change. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 [4]: https://chromestatus.com/feature/5647541725036544 Bug: 1071085, 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218702 Reviewed-by: Raymond Toy <rtoy@chromium.org> Reviewed-by: Yuki Shiino <yukishiino@chromium.org> Commit-Queue: Hongchan Choi <hongchan@chromium.org> Cr-Commit-Position: refs/heads/master@{#779052}
…rocessor.process(), a=testonly Automatic update from web-platform-tests Avoid memory allocation in AudioWorkletProcessor.process() Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. [3] This is an API change [4], but the real world impact would be negligible because there's no functionality change. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 [4]: https://chromestatus.com/feature/5647541725036544 Bug: 1071085, 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218702 Reviewed-by: Raymond Toy <rtoy@chromium.org> Reviewed-by: Yuki Shiino <yukishiino@chromium.org> Commit-Queue: Hongchan Choi <hongchan@chromium.org> Cr-Commit-Position: refs/heads/master@{#779052} -- wpt-commits: 48a5574b7e1a3d7d952a4b9fe84b049375773e42 wpt-pr: 24093
I agree that using the automation rate to determine the length of the |
Something not yet discussed here is what should happen after I don't want to make available for reading the float32 values from an I assume there's no good reason for a client to transfer |
Eventually we have to specify an algorithm for Chrome's current impl does not touch ArrayBuffer if its shape is mutated (i.e. transferred) and will be recreated (re-allocation) in the next call. Crippling a processor into an unusable state is basically a breaking change, and that's what I wanted to avoid as I mentioned above. |
…rocessor.process(), a=testonly Automatic update from web-platform-tests Avoid memory allocation in AudioWorkletProcessor.process() Based on the spec [1], the current implementation of AudioWorkletProcessor needs to create a new data container (i.e. WebIDL sequence<>) for input, output, and param arrays. With the new spec change [2], this CL changes the overall design of the audio processing callback: 1. Moves the processing call from AudioWorkletGlobalScope to AudioWorkletProcessor object. 2. AudioWorkletProcessor now keeps the data container within the object and allocate memory when it is needed. The preliminary benchmark shows the sizable improvement in the audio stream quality. The glitch score (= buffer underrun/total callback) is improved by ~9x in the low-tier machine. [3] This is an API change [4], but the real world impact would be negligible because there's no functionality change. [1]: https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs [2]: WebAudio/web-audio-api#1933 (comment) [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=1086665#c2 [4]: https://chromestatus.com/feature/5647541725036544 Bug: 1071085, 1086665 Change-Id: I3e664754973d4d86649d38c1807c6b9d7830fb96 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218702 Reviewed-by: Raymond Toy <rtoy@chromium.org> Reviewed-by: Yuki Shiino <yukishiino@chromium.org> Commit-Queue: Hongchan Choi <hongchan@chromium.org> Cr-Commit-Position: refs/heads/master@{#779052} -- wpt-commits: 48a5574b7e1a3d7d952a4b9fe84b049375773e42 wpt-pr: 24093
So, there's a couple of things that need to be done here, right?
|
It's been a while since this issue was assigned (#1933 (comment)). Perhaps we need to escalate this? @padenot I can assign this to myself again to get the ball rolling, if that's better. |
@padenot is out for a bit. Assigning to you. I think we've all agreed on the approach. |
There is an option of providing the frozen behavior for the container arrays/objects through a proxy. That can prevent modification of the containers by content but allow the implementation to change properties on a object. This avoids the need to re-create an array/object and all its ancestors when the implementation needs to dynamically change a container. |
Instead of `sequence<sequence<Float32Array>>`, use `FrozenArray<FrozenArray<Float32Array>>`. Define a callback function as well.
https://webaudio.github.io/web-audio-api/#rendering-loop says 'Let
processFunction
be the result of aGet(O=processor, P="process")
', and soprocessFunction
is an ECMAScript entity.The
process()
method is not defined as WebIDL callback type, but its parameters appear to have WebIDL types.https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs says that
inputs
has typesequence<sequence<Float32Array>>
and links to the WebIDL type https://heycam.github.io/webidl/#idl-Float32Arrayhttps://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-parameters says
parameters
is "A map of string keys and associated Float32Arrays", also linking to https://heycam.github.io/webidl/#idl-Float32Array.Is this https://heycam.github.io/webidl/#idl-record ?
The text was updated successfully, but these errors were encountered: