deislabs / wagi

Write HTTP handlers in WebAssembly with a minimal amount of work
Apache License 2.0
889 stars 44 forks source link

Stream chunked data out of guest modules instead of buffering #115

Open technosophos opened 3 years ago

technosophos commented 3 years ago

Right now we buffer the entire HTTP payload before sending to the client. That is really bad performance for things like images. We should instead be able to send chunked data to the client.

technosophos commented 3 years ago

/cc @fibonacci1729

itowlson commented 3 years ago

Do you envisage asyncifying the call into the module, so that we can be returning the first bytes of the response as soon as the Wasm code produces them? Or are you just thinking of trying to reduce the copies between the stdout pipe, the buffer and the response body object?

itowlson commented 3 years ago

Why did I think we would need to asyncify the call into the module? Well, we can't map stdout into a pipe that feeds directly into the response stream, because we need to do some processing on the beginning of the stream to convert top matter to headers. But I wonder if we could do that with some clever pipe/stream infrastructure so that it happens automatically as data is written to/read from the pipe.

ThingsThatSoundEasierThanTheyInevitablyTurnOutToBe

radu-matei commented 3 years ago

https://github.com/bytecodealliance/wai-bindgen/pull/82 and streams should help with this.