ThorstenHans opened PR #11591 from ThorstenHans:chore/wasio-streaming-chunksize to bytecodealliance:main:
While moving vast amounts of data using
wasi:iostreams, we found the existing max chunk size of 4KB adding a lot of overhead. To reduce the number of chunks that one must create, this PR changes the max chunk size from 4KB to 64KB for all blocking write operations.Here a simple table outlining how many chunks are required based on max chunk size being either 4KB or 64KB:
File Size No. of Chunks (4 KB) No. of Chunks (64 KB) 16 KB 4 1 100 KB 25 2 1 MB 256 16 10 MB 2,560 160 100 MB 25,600 1,600 1 GB 262,144 16,384 10 GB 2,621,440 163,840 100 GB 26,214,400 1,638,400 I'll leave this in a draft state for now and will collect additional data on performance improvements
pchickey commented on PR #11591:
The
blocking-write-and-flushchunk size is specified in the wasi-io spec, not in wasmtime, so we actually can't make this change without a breaking change to Wasi, which won't happen at this point because streams are completely redone as part of the component model as part of Wasi 0.3.Basically,
blocking-write-and-flushis a convenience method that exists primarily to make sure its always possible to write a debug message without getting any sort of protocol right. Its not meant to be the fast path. Instead, you should usecheck-write,write, and polling on apollablein order to get the maximum performance out of anoutput-stream. So, please check if you can start using a larger chunk size when switching to that part of the interface. We have a lot more flexibility with how those methods are implemented.
ThorstenHans commented on PR #11591:
@pchickey thanks for the feedback.
the blocking apis are actually used in a 3rd party dependency on the guest side. I'll reach out to one of the maintainers to discuss and suggest the change you mentioned.
Q: You mentioned the chunk size being "specified" in the wasi-io spec, I can only find
4096being referenced in comments: https://github.com/WebAssembly/wasi-io/blob/73222408bd3de90c8a9144c9ece02bb606c834f6/wit/streams.wit#L154Any other places you can point me to?
pchickey commented on PR #11591:
The comments are the spec, yes.
Last updated: Dec 06 2025 at 06:05 UTC