Open Timbus opened 3 years ago
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?
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.
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