kohttp icon indicating copy to clipboard operation
kohttp copied to clipboard

possible performance problems

Open alosdev opened this issue 4 years ago • 1 comments

https://github.com/rybalkinsd/kohttp/blob/188b5c5a6e770a167fabcddc928dd4978af2a230/kohttp-jackson/src/main/kotlin/io/github/rybalkinsd/kohttp/jackson/ext/ResponseExt.kt#L69

in the following line, the library makes a string out of the response and it loses the purpose of a stream reader. Would it be possible to use the InpputStream to leverage the way how Jackson is working? Also with very large responses, it would raise some memory pressure.

alosdev avatar Jun 10 '20 17:06 alosdev

Thanks for posting this issue @alosdev!

Overall, It's a great idea to introduce a simplified API to work with response streaming.

Indeed, in the quoted file we load the whole response. The main idea of .toType extension is to deserialise simple/small bodies as type T

val simple: SimpleClass? = it.toType()

In this case we have an extra allocation(for tmp string) + sequential processing vs streaming processing overhead. In my mind it would be great to have a benchmark to make a decision. Do you have any use case in your mind?

From my understanding getting deserialized type T or JsonNode itself will not radically change the situation (the whole object will be in memory after parsing) However parsing arrays of to Stream<T> or fetching a particular filed(sub-object) from a huge body could help. Do you have any thoughts about API?

rybalkinsd avatar Jun 11 '20 11:06 rybalkinsd