I've been running into an issue with Emscripten, where I cannot use a 
shared WebAssembly.Memory (ie., backed by a SharedArrayBuffer) in a 
single-threaded build. The rationale for this is to be able to use the 
Emscripten heap as a shared state with other workers / the UI thread. 
Specifically, it would allow us to directly copy data to the heap in other 
threads, avoiding to copy data.

Our scenario looks like this:
(1) We run a (single-threaded) WebAssembly module in a worker in a  
long-running synchronous call;
(2) From within the synchronous call stack, the wasm module calls into JS 
to dispatch some work to the UI thread;
(3) We currently COPY the data from the WebAssembly.Memory heap to a 
separate SharedArrayBuffer, which we then postMessage to the main thread.
(4) The worker then uses a wait/notify pattern to block the Emscripten call 
stack until the UI thread has passed back a result on the SharedArrayBuffer
(5) The UI thread can meanwhile perform some asynchronous work (eg., 
IndexedDB, etc.) and store the response in the SharedArrayBuffer, then 
notify the waiting worker.
(6) The waiting worker then has to COPY the result from the 
SharedArrayBuffer back onto the Emscripten heap and return.

In effect, we're performing two (expensive) copies. If the Emscripten heap 
was using a SharedArrayBuffer, we could trivially share that with the UI 
thread and merely pass offsets on the heap around.

So in summary, are there any plans to supporting an SAB-backed 
WebAssembly.Memory for scenarios like these? I understand that a 
multi-threaded build could accomplish this. However, the extra complexity 
of the WebAssembly threading model (especially when running the WebAssembly 
module inside a worker) is not really acceptable in this case.

Soeren 

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/283659cd-4e07-4913-a185-e4e9495f8d12n%40googlegroups.com.

Reply via email to