Make from_parts a LRU to increase the chance we can preserve the internal cache#1434
Make from_parts a LRU to increase the chance we can preserve the internal cache#1434
from_parts a LRU to increase the chance we can preserve the internal cache#1434Conversation
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
URLobjects quite frequently. BecauseURLobjects are immutable, when this happens theself._cacheis lost and has to be reconstructed for the newURLobject 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_cachewhich ensuresself._cacheis 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.