-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[AUDIO_WORKLET] Optimised output buffer copy #24891
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
Open
cwoffenden
wants to merge
16
commits into
emscripten-core:main
Choose a base branch
from
cwoffenden:cw-aw-optimised-copy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+279
−185
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5a70474
to
99f4c12
Compare
e19d4fd
to
348932f
Compare
2313240
to
748c167
Compare
juj
reviewed
Aug 13, 2025
4cba21c
to
998ac6b
Compare
sbc100
reviewed
Aug 14, 2025
This takes into account multiple multi-speaker outputs (the spec labels 18).
b57d103
to
5186686
Compare
It's not possible to merge the output data copy into a single |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A reworking of #22753, which "improves the copy back from the audio worklet's heap to JS by 7-12x depending on the browser." From the previous description:
Since we pass in the stack for the worklet from the caller's heap, its address doesn't change. And since the render quantum size doesn't change after the audio worklet creation, the stack positions for the audio buffers do not change either. This optimisation adds one-time subarray views and replaces the float-by-float copy with a simple
set()
per channel (per output).The existing interactive tests (written for the original PR) can be run for comparison:
These test various input/output arrangements as well as parameters (parameters are interesting because, depending on the browser, the sizes change as the params move from static to varying).
The original benchmark of the extracted copy is still valid:
https://wip.numfum.com/cw/2024-10-29/index.html
This is tested with 32- and 64-bit wasm (which required a reordering of how structs and data were stored to avoid alignment issues).
Some explanations:
WasmAudioWorkletProcessor
constructorprocess()
call are split into aligned struct data (see the comments) and audio/param dataASSERTIONS
are used to ensure everything fits and correctly alignsFuture improvements: the output views are sequential, so instead of of being individual views covering each channel the views could cover one to however-many-views needed, with a singleset()
being enough for all outputs.