Mango icon indicating copy to clipboard operation
Mango copied to clipboard

Reuse downloader client to help lower network overhead

Open Timbus opened this issue 4 years ago • 2 comments

https://github.com/hkalexling/Mango/blob/df51406638d7266a990bd2b660e3bcc2d2d71c53/src/mangadex/downloader.cr#L142 Should probably reuse a connected client for downloads, which should reduce overhead a tiny amount.

Just hang on to a client using a lazy getter I suppose: https://crystal-lang.org/api/master/HTTP/Client.html#reusing-a-connection

Timbus avatar Dec 18 '20 01:12 Timbus

Thanks for the suggestion! I am not very familiar with the Crystal compiler internals and the GC but I think the performance improvement would be very minimal if any. But I guess it doesn't hurt to optimize a bit :P Are you interested in submitting a PR to the dev branch?

hkalexling avatar Dec 18 '20 15:12 hkalexling

Sure thing: https://github.com/hkalexling/Mango/pull/130

Also regarding performance, the problem with reconnecting each time is that you need to allocate a socket, do the TCP handshake, generate new TLS keys, etc etc.. So it's not really related to Crystal's performance (which is excellent, yes), it's mostly network related. Avoiding this overhead is mostly for mangadex's benefit, but it does slightly benefit the client too.

Timbus avatar Dec 19 '20 09:12 Timbus