Skip to content

Conversation

ThorstenHans
Copy link

While moving vast amounts of data using wasi:io streams, 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

This commit changes the max chunk size for blocking operations (defined by `streams::HostOutputStream` from 4kb to 64kb.

Signed-off-by: Thorsten Hans <[email protected]>
@pchickey
Copy link
Contributor

pchickey commented Sep 2, 2025

The blocking-write-and-flush chunk 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-flush is 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 use check-write, write, and polling on a pollable in order to get the maximum performance out of an output-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
Copy link
Author

@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 4096 being referenced in comments: https://github.com/WebAssembly/wasi-io/blob/73222408bd3de90c8a9144c9ece02bb606c834f6/wit/streams.wit#L154

Any other places you can point me to?

@pchickey
Copy link
Contributor

pchickey commented Sep 3, 2025

The comments are the spec, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants