-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[AUDIO_WORKLETS] Move code off the main thread in locks test #25276
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
base: main
Are you sure you want to change the base?
Conversation
|
|
122be37 to
8dcef4c
Compare
1b37d5a to
de0aebb
Compare
|
|
d8bd45d to
f81f4e3
Compare
That could be from some other audio worklet bug, I've seen |
|
I've also seen plain old |
|
This flake seems to be Chrome-specific btw - the flake does not occur on Firefox. I wonder if there could be a Chrome bug or improvement possible? |
|
I saw a few failures with the earlier code after the We're not running anything from Emscripten 4 in production yet (only in development), but what we've seen for years in the logs are errors when unloading the page. Usually some timeout call or worker is still running after the page is partially unloaded. |
If it is down to the worker's interaction with main, it might be why I see I had this about every other run whilst trying to get all ticks for this PR. |
But this isn't even doing any audio code, it's essentially a message passing worker. |
|
#25312 seems to fix |
5695571 to
e8ee1b3
Compare
I added the same explicit shutdown here too to see how that goes. So far the unrelated |
|
If you want to run more iterations faster I have a helper option |
|
This should be good to land, since it moves code off the main thread and add the exit hang fix from #25312. |
Also fix erroneous looking switch fall-through.
This reverts commit 82405f7.
|
These changes are still relevant. |
|
This seems like its working around a larger issue here which is that audio worklet code cannot, in general, synchronize with the main thread. Is that true? If so, should we not document that? It seems like a pretty huge issue TBH. Can we come up with a way to detect this kind of synronization and warn about? I can't think of any way sadly, since the APIs uses are mostly just atomics and its not possible to tell which thread is being interacted with. I guess I'm ok landing this change to make the tests less flaky but we should have some plan to update the docs I think. Would it be simpler to just say the audio worklet cannot ever block on other threads at all? Its seems like that is likely the intent of the API anyway, that it should never block. |
|
(I guess the previous comment is really just about #24213) |
|
I think until recently it was possible to use futexes between the main and audio thread*, but something changed in Chrome that broke this. Let me delve into the spec and see what it says (I've already forgot the finer points since writing this), then think about how to document this. *we shipped a product for years doing this before shifting more work off the main thread. |
The spec seems pretty clear to me: "Implementations can run worklets wherever they choose (including on the main thread).". I think we (emscripten) perhaps overlooked or misunderstood this. |
Presumably this means that audio worklet work run on any given web worker too. |
|
Actually I just heard back from webaudio folks who pointed out that spec for AudioWorkletProcessor says: "This interface represents an audio processing code that runs on the audio rendering thread." They also said that chrome in particular runs on a pool of backing threads, not the main thread. This means I that this change should not be necessary. Perhaps there is bug in chrome, or perhaps there is a bug in our stuff, but this seems like just sidestepping the issue rather than tracking it down. |
[snip] I'll look into it. There was a change in Chrome that seemed to break this all of a sudden. |
Did you notice it in your shipping code or just here in the unit tests? |
Only in the unit test, but that might be a logic error fixed when going to a worker as a side effect. I'll look further into it and I'll check in with our devs that use this, because it's possible code moved off the main thread. The unit test ended up being a test of the API rather than something to hammer the locks (ideally it'd be a queue, with multiple entries pushed from a timeout on the main thread and popped from the audio thread). |
|
I extended the test to take a |
Having spent some time with it, and having changed the code to allow switching between main and worker threads (harnessing the power of messy macros), I can't say why it does but the assert will eventually fail from the audio thread in I will continue looking because I'd like an answer. |

ProcessAudio()behaves like it's running on the main thread, so spin locks are also blockingMainLoop()from running*. I removed the previous workaround of a counter in the AW process callback, used to only have interaction between the audio and main thread after a delay.The previous main thread's code is now run in a worker, which still tests the spinlocks from the AW's side.
*it may also just be that the main thread is used to schedule the callbacks.