logoalt Hacker News

pikertoday at 9:29 AM3 repliesview on HN

Great piece, OP. We work in WASM and are considering web workers to help with rendering documents off the main thread in that context. I was surprised to read that ArrayBuffer is moved by reference only! Might be an option. Thanks for putting this together.


Replies

bastawhiztoday at 1:39 PM

ArrayBuffer is copied by default unless you pass it as a special transferable object. But only the current owner of the buffer can use it.

If you need to read and write from both threads at once, you need to look at SharedArrayBuffer.

gioandthemachintoday at 10:38 AM

haven't done this for documents, but for canvas rendering transferControlToOffscreen() worked better than moving ArrayBuffers. It hands the canvas to a worker that draws directly, no pixles over postMessage at all.