-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Unconditionally exposing domain specific API for all scripts #1120
Comments
Thanks for filing this issue here so that the discussion can reach more people who are interested in JavaScript. For interruptability: I wonder if Promises interact with this concern. My understanding is that, for HTML in general, all Promise-queued tasks ("microtasks") run to completion before resuming the HTML-level task queue. Is this the case for AudioWorklets as well? Is this appropriate? If not, I'm not sure if anything needs to be changed at the JavaScript level, or just the way it's embedded. Other than that, it's hard for me to think of other JS functionality which may be added to the JavaScript specification in the future which may want to call into browser APIs or block (just synchronous computation work). For authoring concerns: This one seems a bit tricker. How do you draw the line exactly? Do you have any examples from other specifications which made a deliberate decision to include or exclude an interface in |
I reckon that I need to read up on Promises in the ECMAspec. Since
Other than that, exposition of a Web Platform API is controled by I think you're right that this is partly an embedding issue (for now, granted there are now other ECMAScript feature that are going to be a bit incompatible with the |
@padenot do you think there's something actionable here for ECMAScript, or can this be closed? |
We can probably close this, thanks. |
I think the main takeaway is that taking on large dependencies as is sometimes talked about, such as importing |
I think this got closed a bit quickly. This is an important perspective that we might want to discuss further. We are considering more expansion of the JS standard library, and this is a big proposed design goal. |
Since https://github.com/tc39/proposal-javascript-standard-library now exists, I think tc39/proposal-built-in-modules#16 is a better place for further discussion. |
I'm opening this off of whatwg/webidl#468 (comment), that suggests that more API will be available in ECMAScript in the future, and therefore (I think, not knowing in detail whether it is possible to opt-out at the WebIDL level) in all
*GlobalScope
s on the Web platform.First I'll provide a bit of context, then summarize the concerns I (and probably some other folks in the AudioWG) have here.
Context: real-time audio programming on the web
The Audio Working Group has standardized the
AudioWorklet
API that allows running script in a special environment, with the explicit and sole goal of being able to do real-time audio processing. A summary of the processing model of this API is summarized below.Considering you have an
AudioContext
that has instantiated anAudioWorklet
object, that loads a script in anAudioWorkletGlobalScope
:process
method of theAudioWorkletProcessor
associated to theAudioWorkletNode
, passing it an input buffer and an output buffer (bothFloat32Array
s).The steps above happen continuously. To get a sense of scale, in a typical situation, such a system would be processing 10ms buffers each time. With a sound card clocked at 48kHz (again very typical), it is necessary to process a 480 frames buffer 100 times a second. Failure in returning on time even once is considered a critical failure of the system. This 10ms period is called a rendering quantum.
We have some code examples in https://webaudio.github.io/web-audio-api/#AudioWorklet-Examples.
Concerns
The concerns here can be split into two groups: implementation concerns and authoring concerns
Implementation concerns
Interruptiblity: it is desirable to be able to brutally interrupt the execution of a script running in the
AudioWorkletGlobalScope
, for example if it's running for too long (much more than a rendering quantum), to both prevent a denial of service or a resource abuse (which would be tempting: this script is likely to be running on a high priority thread).If the script calls into browser APIs, it's likely that it won't be interruptible until it has returned.
Blockiness: it is critical to never block the thread that is processing the audio. Allocating memory, taking locks, loading in a shared library, making system calls can all be blocking operations. I don't think there are strong guarantees on how to implement browser API so that they don't block, but in practice, what is available today is more or less OK (Regular expressions and the
Date
object being the two obvious exceptions).Authoring concerns
Having high-level APIs (the Internationalization is an example that has been brought up in the issue linked at the beginning of this issue) exposed in the
AudioWorkletGlobalScope
sends the wrong message to authors. AnAudioWorkletGlobalScope
(and I'd go as far as saying other Worklets, such as thePaintWorklet
) is never the right location to do some i18n work, regardless of the use-case or application, so it seems wrong to be able to access it there.Now, we can always say "don't do this and that in an
AudioWorklet
", and maybe that's fine but at least there should be a discussion about it.The text was updated successfully, but these errors were encountered: