Open vilgotf opened 5 months ago
How would we even do lazy deserialzation? Or do you simply mean to defer the deserialzation to when it is actually looked at?
its possible in theory but i doubt serde supports it and im not sure the complexity this brings is worth the performance gain, in some cases it may even lead to worse performance when people repeatedly deserialize the stream's items
How would we even do lazy deserialzation? Or do you simply mean to defer the deserialzation to when it is actually looked at?
Hyper streams the response body by default so we just need two streaming adapters: &[u8] -> &str
and &str -> T
. For inspiration, tokio-websockets
contains a streaming UTF-8 validator.
its possible in theory but i doubt serde supports it
Serde does not support streaming adapters but it's trivial to do so ourselves. We deserialize upon hitting a comma if our counter of braces and brackets are zero (i.e. the comma separates elements in the top level array).
and im not sure the complexity this brings is worth the performance gain, in some cases it may even lead to worse performance when people repeatedly deserialize the stream's items
The stream (AsyncIterator
) would consume the response body
Would this not cause potentially more memory to be used since the string has to valid for as long as the deserilizer is?
Instead of
Response::models
being anasync fn -> Result<Vec<T>, E>
it should return a type implementingStream<Item = Result<T, E>>
andIntoFuture<Output = Result<Vec<T>, E>>
. This allows for lazy deserializing the response and potentially skip the (often unused)Vec
buffer.Inspiration: https://github.com/abdolence/axum-streams-rs