Re: [whatwg/streams] Why does the `read` method of `ReadableStreamBYOBReader` class, need to _transfer_ the buffer it is provided? (Issue #1348)

amn left a comment (whatwg/streams#1348)

> [@amn](https://github.com/amn) Which specification that forbids what? 

I was quoting your own earlier reply which stated:

> The Wasm/JS specifications explicitly forbid a non-shared array buffer's contents from being mutated concurrently to the execution of the Wasm/JS code.

Nevermind, however -- you clarified it all in your latest comment -- I was able to understand how the `"WebAssembly.Memory"` "detaching" key de-facto forbids detaching/transferring of the buffers held by WASM memory objects.

Seems like supporting JS-WASM "zero-copy" through allowing `read` to work on `SharedArrayBuffer` as held by WASM memories (which currently does not work), would be one way to go about it indeed.

I do have a case for it, but I can't demonstrate any performance wins unless I can actually execute the case, which I cannot :) Conceptually, I wrote an MD5 computation routine in WASM (obligatory: yes, I am well aware MD5 is old an broken -- there's plenty of code that still needs it, for non-cryptographically sensitive applications), and it needs to copy every chunk of data fed to the MD5 machine, which is a case of unnecessary copying. Anyway, since I can't run the code I wrote using `read` which throws trying to detach the WASM memory buffer, I have no means to test expected performance benefits. Using `SharedArrayBuffer` by initializing the [imported] instance memory with `{ shared: true }` also doesn't work (runtime error), so I am unsure how you want me to present my use case -- as a README/proposal postulating/hypothesising something? I can do that.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1348#issuecomment-3148335784
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/issues/1348/3148335784@github.com>

Received on Sunday, 3 August 2025 10:50:34 UTC