-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache IP Address parsing #1086
Cache IP Address parsing #1086
Conversation
In _encode_host, the most expensive thing is converting the string to an ip address to normalize it. Its much more expensive than _idna_encode which we already cache.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1086 +/- ##
=======================================
Coverage 93.05% 93.06%
=======================================
Files 31 31
Lines 4408 4424 +16
Branches 364 370 +6
=======================================
+ Hits 4102 4117 +15
- Misses 280 281 +1
Partials 26 26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Ran for a few hours, manual testing and LRU hit rate look good. Working as expected |
What do these changes do?
In
_encode_host
, the most expensive thing is converting the string to an ip address to normalize it when the URL has an ip address instead of a hostname. Its much more expensive than_idna_encode
which we already cache.I always wondered the aiohttp benchmarking we did for Home Assistant performed worse when using 127.0.0.1 vs a hostname as it was confusing that that the dns lookup it would be faster, but its cached and avoids the ip address object creation for every iteration in yarl. I didn't look deep enough in the stack to look at yarl when we did that.
In hindsight, it should have been a bit more obvious since IP addresses are more common than names for Home Assistant because there is so much local network traffic and ips are usually discovered via mdns or some other method.
Are there changes in behavior for the user?
no
before

after
