Skip to content

feat: implement heapq for tracking cache expire times#1465

Merged
bdraco merged 30 commits into
masterfrom
heapq
Jan 9, 2025
Merged

feat: implement heapq for tracking cache expire times#1465
bdraco merged 30 commits into
masterfrom
heapq

Conversation

@bdraco

@bdraco bdraco commented Jan 8, 2025

Copy link
Copy Markdown
Member

Implements a heapq to track cache expire to avoid enumerating the whole cache every 10s

fixes #1464

technically breaking change: make set_created_ttl protected as they should never be called externally. It was not expected that they ever would have been though and the behavior was likely not correct if they were being called externally.

technically breaking change: reset_ttl has been removed as we should not be mutating existing records as it can cause unexpected behaviors. They should be replaced in the cache instead as it has action at a distance side effects for downstream.

@codspeed-hq

codspeed-hq Bot commented Jan 8, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #1465 will not alter performance

Comparing heapq (e3ba478) with master (e05055c)

Summary

✅ 3 untouched benchmarks

@bdraco

bdraco commented Jan 8, 2025

Copy link
Copy Markdown
Member Author

Problem is created is not immutable.. set_created_ttl

@bdraco

bdraco commented Jan 8, 2025

Copy link
Copy Markdown
Member Author

set_created_ttl should probably be a private api to prevent mistakes because it will need to be rewarded to the cache after adjusting

We also need tests to make sure created and ttl never end up in eq or hash

Comment thread tests/services/test_browser.py Outdated
Comment thread tests/services/test_info.py Outdated
Comment thread tests/test_handlers.py Outdated
Comment thread tests/test_handlers.py Outdated
Comment thread tests/test_handlers.py Outdated
Comment thread tests/test_handlers.py Outdated
@codecov

codecov Bot commented Jan 8, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.78%. Comparing base (e05055c) to head (e3ba478).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1465   +/-   ##
=======================================
  Coverage   99.78%   99.78%           
=======================================
  Files          30       30           
  Lines        3289     3311   +22     
  Branches      448      453    +5     
=======================================
+ Hits         3282     3304   +22     
  Misses          5        5           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread src/zeroconf/_cache.py
Comment thread src/zeroconf/_cache.py
Comment thread src/zeroconf/_cache.py
Comment thread src/zeroconf/_handlers/record_manager.py Outdated
Comment thread src/zeroconf/_handlers/record_manager.py Outdated
Comment thread src/zeroconf/_cache.py
Comment thread src/zeroconf/_cache.py
Comment thread src/zeroconf/_cache.py
Comment thread src/zeroconf/_dns.py
Comment thread src/zeroconf/_handlers/record_manager.py Outdated
Comment thread src/zeroconf/_cache.py Outdated
@bdraco bdraco marked this pull request as ready for review January 9, 2025 00:15
@bdraco bdraco merged commit 09db184 into master Jan 9, 2025
@bdraco bdraco deleted the heapq branch January 9, 2025 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache cleanup scales poorly with many entries

1 participant