wagi icon indicating copy to clipboard operation
wagi copied to clipboard

Stream chunked data out of guest modules instead of buffering

Open technosophos opened this issue 4 years ago • 4 comments

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 avatar Aug 25 '21 16:08 technosophos

/cc @fibonacci1729

technosophos avatar Aug 25 '21 16:08 technosophos

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 avatar Nov 15 '21 21:11 itowlson

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

itowlson avatar Nov 15 '21 23:11 itowlson

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

radu-matei avatar Nov 15 '21 23:11 radu-matei