-
-
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
Make from_parts
a LRU to increase the chance we can preserve the internal cache
#1434
Conversation
CodSpeed Performance ReportMerging #1434 will improve performances by 85.74%Comparing Summary
Benchmarks breakdown
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1434 +/- ##
==========================================
- Coverage 96.11% 96.10% -0.02%
==========================================
Files 31 31
Lines 5871 5855 -16
Branches 348 348
==========================================
- Hits 5643 5627 -16
Misses 202 202
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. |
Hit rate looks great
Also we end up with a massive improvement in the |
from_parts
and LRU to increase the chance we can preserve the internal cache
from_parts
and LRU to increase the chance we can preserve the internal cachefrom_parts
a LRU to increase the chance we can preserve the internal cache
2024-11-29 19:42:14.766 CRITICAL (SyncWorker_5) [homeassistant.components.profiler] Cache stats for lru_cache <function from_parts_uncached at 0x7f1095e91440> at /usr/local/lib/python3.13/site-packages/yarl/_url.py: CacheInfo(hits=13122, misses=228, maxsize=128, currsize=128) |
Thats after startup ~100 minutes |
We end up doing the same modification to
URL
objects quite frequently. BecauseURL
objects are immutable, when this happens theself._cache
is lost and has to be reconstructed for the newURL
object that is produced. Additionally, we had ended up with a few places where theobject.__new__(URL)
was inlined because it was faster. We can move this all behind anlru_cache
which ensuresself._cache
is preserved if the parts are in the cache which is the common case for most applications. With this change we can centralize most of the__new__
construction and make the code a bit more DRY.