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

Guidance in exposing some APIs only off the main thread #360

Closed
dontcallmedom opened this issue Jan 28, 2022 · 4 comments · Fixed by #404
Closed

Guidance in exposing some APIs only off the main thread #360

dontcallmedom opened this issue Jan 28, 2022 · 4 comments · Fixed by #404
Assignees
Labels
Agenda+ Status: Consensus to write We have TAG consensus about the principle but someone needs to write it (see "To Write" project) Topic: JS

Comments

@dontcallmedom
Copy link

dontcallmedom commented Jan 28, 2022

Following up on #325, which has already quite a bit of background on this:
is it appropriate to use non-exposure of an API on Window as a way to force developers to not do things on the main thread?

That question has emerged in WebCodecs, WebRTC Encoded Transform, Media Capture Transform, WebNN, File API.

@dontcallmedom
Copy link
Author

in case it helps, WebIDLpedia now gives information on exposure sets, in particular which interfaces are exposed only in a given exposure, e.g. for DedicatedWorker:

The following interfaces are exposed exclusively in [DedicatedWorker] realms:

  • DedicatedWorkerGlobalScope
  • MediaStreamTrackProcessor
  • RTCRtpScriptTransformer
  • RTCTransformEvent
  • VideoTrackGenerator

@annevk
Copy link
Member

annevk commented Jan 28, 2022

I think the answer here is yes. E.g., see precedent of having synchronous I/O APIs only available in dedicated workers. (You typically do not want to block shared/service workers either.)

@dontcallmedom
Copy link
Author

dontcallmedom commented Jan 28, 2022

To @annevk's point, I think guidance in this space needs to recognize two distinct situations:

  • blocking calls (e.g. synchronous I/O)
  • triggers for expected-to-be CPU-compute-intensive processing that can make the main thread unresponsive (e.g. MediaStreamTrackProcessor, RTCTransformEvent) - the APIs themselves aren't blocking, but the type of operations they support can make the main thread janky because of their CPU usage.

I think there is probably no controversy around recommending against the 1st type.

There is obviously controversy on the 2nd type.

Part of it I think is that APIs of the 2nd type can be used on the main thread in a way that guarantees it would not impact it - e.g. MediaStreamTrackProcessor could be used to trigger GPU-only processing which presumably would have zero risk of slowing down the main thread.

(as discussed before, I'm the opinion that not exposing them on Window is a reasonable approach to avoiding footguns, but I also want to make sure we understand the problem clearly)

@alvestrand
Copy link

Note that all the five interfaces only available in DedicatedWorker are the hotly contested items in WEBRTC.
It's nice to see that there is no such pattern elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agenda+ Status: Consensus to write We have TAG consensus about the principle but someone needs to write it (see "To Write" project) Topic: JS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants