Re: [whatwg/streams] Could a byte stream read directly into and out of a SAB (w/o transfer)? (#757)

bvisness left a comment (whatwg/streams#757)

We've been experimenting in Firefox with allowing SharedArrayBuffer to be used with BYOB streams. Initial results are very positive. The tracking bug can be found [here](https://bugzilla.mozilla.org/show_bug.cgi?id=1949223), but I will share my test results here as well.

We tested this out on an online profiler called [Spall](https://gravitymoth.com/spall/spall.html). When it loads a trace file, it processes it in 10MB chunks. The live version does this by using `FileReader.readAsArrayBuffer()` and copying the ArrayBuffer contents into WASM memory. It then runs WASM code to process the chunk. We modified Spall to use shared WASM memory and updated the loading code to use `Blob.stream()` and BYOB, keeping the rest of the code the same.

We profiled loading a 2GB trace file on an M4 Mac and saw very positive results ([before](https://share.firefox.dev/45vLvL4) -> [after](https://share.firefox.dev/4mEoqNj)):

- Total time: 14.44s -> 14.17s (1.8% speedup)
- Overall I/O speedup of ~22%
- Total memory allocated: 2.1GB -> 38MB
- Peak memory usage: 1.38GB -> 23.2MB
- Major GCs: 1 -> 0

So, 22% speedup on the I/O itself, and 50x memory savings. Very good numbers! Frankly I did not expect to see such a good speedup given that the workload is about 85% WASM compute.

Given these results, and the ease of implementation, I definitely think this is worth pursuing further.

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

Message ID: <whatwg/streams/issues/757/3190021102@github.com>

Received on Thursday, 14 August 2025 22:19:52 UTC