Httpx: Cache NETRC logins after first lookup

Created on 25 Sep 2019  Â·  4Comments  Â·  Source: encode/httpx

As noted in #364, looking up NETRC logins is eating 25% of request time (!) — see get_netrc_login() below (times are absolute for a series of 1000 requests).

The .netrc file typically won't change across a session. So while we can't avoid paying that performance cost on the first request, we can definitely cache the NETRC credentials on the client once we looked them up (even if they don't exist).

This improvement would give us a 25% performance boost (on localhost, so ignoring network latency), getting us closer to aiohttp speeds according to this benchmark.

good first issue perf

Most helpful comment

Could you assign me this topic if someone else is not interested?

All 4 comments

Could you assign me this topic if someone else is not interested?

Sure @cansarigol, go for it!

I added lru_cache but I'm not sure that it suits or what its max size should be? What do you think?

btw httpxprof is awesome @florimondmanca

Sounds like a great call to me, yup.

Related - we shouldn't pay much attention to "micro-benchmarking" of HTTP clients - it's not at all obviously a meaningful metric. We shoud be interested in code-space latency overhead, but it's usually likely to be dwarfed by network latency, and we should be interested in maximum sustainable concurrency, but it's usually likely to cap out similarly across any other Python async implementations.

Was this page helpful?
0 / 5 - 0 ratings