task-worklet icon indicating copy to clipboard operation
task-worklet copied to clipboard

How does TaskQueue/TaskWorklet tie into WASM threads?

Open pshihn opened this issue 7 years ago • 5 comments

With threads in WASM coming up, there may be some merit to tying them with Task Queues

pshihn avatar Nov 13 '18 22:11 pshihn

I think right now there isn't really an interaction between the two. The polyfill would allow WASM as it is implemented using Workers for the threadpool, however the proposal (publishing soon) and our experimental implementation in Chromium use a proper Worklet backing in the pool and thus don't allow for WASM usage.

developit avatar Nov 15 '18 19:11 developit

It's possible to use WebAssembly in AudioWorklet in stable Chrome so it's confusing that it's not the case for TaskWorklet

chicoxyzzy avatar Nov 16 '18 09:11 chicoxyzzy

Basically it should be possible to load js module via Worklet.addModule and load+compile+instantiate wasm in this module

chicoxyzzy avatar Nov 16 '18 09:11 chicoxyzzy

Also just found this reference that WebAssembly namespace should be exposed to window, worker and worklet

chicoxyzzy avatar Nov 19 '18 18:11 chicoxyzzy

@chicoxyzzy you're right, I'm not sure why I implied WASM couldn't be used - there's no reason it can't here.

const wasm = WebAssembly.instantiateStreaming(fetch('worklet.wasm'));

class WasmDemoProcessor {
  async process(data) {
    const { instance } = await wasm;
    return instance.exports.doThing(data);
  }
}

registerTask('wasm-demo', WasmDemoProcessor);

developit avatar Nov 21 '18 14:11 developit