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

Worklet agents and the event loop #10136

Open
annevk opened this issue Feb 13, 2024 · 3 comments
Open

Worklet agents and the event loop #10136

annevk opened this issue Feb 13, 2024 · 3 comments
Labels
integration Better coordination across standards needed topic: agent The interaction with JavaScript's agent and agent cluster concepts. topic: event loop topic: worklets

Comments

@annevk
Copy link
Member

annevk commented Feb 13, 2024

As @mhofman discovered in tc39/proposal-shadowrealm#398 (comment) there's something broken about the current setup. Agents are assumed to be 1:1 with an event loop, but we don't define an event loop for worklets (as we don't want them to have one). However, this means that certain features such as FinalizationRegistry effectively crash (see HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry)).

I think this means we either need to have non-event-loop agents that don't expose these features or we need to give worklets a minimal event loop. I think the latter is very much undesirable for good audio, but I'll defer to @padenot on that.

cc @syg @padenot @domenic @rniwa @smaug----

@annevk annevk added integration Better coordination across standards needed topic: event loop topic: agent The interaction with JavaScript's agent and agent cluster concepts. topic: worklets labels Feb 13, 2024
@padenot
Copy link

padenot commented Feb 13, 2024

https://webaudio.github.io/web-audio-api/#rendering-loop has an attempt to make this work.

As far as the Web Audio API is concerned, it's not that it's not possible, it's that the event loop cannot execute traditionally, executing the tasks when there exist: instead, the tasks are processed near the beginning of a "render quantum" when the OS calls a callback on a real-time thread.

We might be able to make this clearer or more correct (if it's not), paging @hoch in any case.

@hoch
Copy link
Contributor

hoch commented Feb 29, 2024

A concept of event loop with real-time constraints would be a decent solution to this problem, but I think that's a rather significant change with so many uncertainties to introduce after a decade of the API launch. So without such system, the rendering loop algorithm that we have in Web Audio API is the best we can do.

+1 on making it more clearer or more correct.

@annevk
Copy link
Member Author

annevk commented Mar 3, 2024

I think the problem now is that there are certain JS APIs that assume there's an event loop (as defined in the HTML Standard), but that's not the case for worklets. So either those JS features cannot work in worklets or they work in some undefined manner.

It does seem like Web Audio attempts to integrate with this maybe through the "associated task queue", but it doesn't seem particularly sound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration Better coordination across standards needed topic: agent The interaction with JavaScript's agent and agent cluster concepts. topic: event loop topic: worklets
Development

No branches or pull requests

3 participants