-
Notifications
You must be signed in to change notification settings - Fork 228
fix: bound _seen_logs and stop retaining exc_info #1717
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
Merged
+214
−47
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
42220db
fix: bound _seen_logs and stop retaining exc_info
bdraco 85ac2ae
refactor: share _mark_seen helper between _logger and _protocol.incoming
bdraco ba5de3a
refactor: switch _mark_seen eviction from clear() to pop() and raise …
bdraco 4cb3ecf
refactor: switch _seen_logs to dict[str, None] for FIFO eviction
bdraco 9a64353
test: pin _mark_seen FIFO eviction and add CodSpeed bench
bdraco ebe1ab2
fix: make _mark_seen safe under free-threaded contention
bdraco 0e25328
fix: drain _seen_logs in a while loop so drift can't inflate the cap
bdraco d3598be
Merge branch 'master' into fix/seen-logs-unbounded-retention
bdraco d6cddb9
fix: drain _seen_logs drift on hit path and pin FIFO by key identity
bdraco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """Benchmark for _logger._mark_seen.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pytest_codspeed import BenchmarkFixture | ||
|
|
||
| from zeroconf._logger import _MAX_SEEN_LOGS, _mark_seen | ||
|
|
||
|
|
||
| def test_mark_seen_hit(benchmark: BenchmarkFixture) -> None: | ||
| """Benchmark the cache-hit path (same key repeated).""" | ||
| seen: dict[str, None] = {"warm": None} | ||
|
|
||
| @benchmark | ||
| def _hit() -> None: | ||
| for _ in range(1000): | ||
| _mark_seen(seen, "warm") | ||
|
|
||
|
|
||
| def test_mark_seen_fill(benchmark: BenchmarkFixture) -> None: | ||
| """Benchmark filling from empty up to the cap (no evictions).""" | ||
| keys = [f"key-{i}" for i in range(_MAX_SEEN_LOGS)] | ||
|
|
||
| @benchmark | ||
| def _fill() -> None: | ||
| seen: dict[str, None] = {} | ||
| for k in keys: | ||
| _mark_seen(seen, k) | ||
|
|
||
|
|
||
| def test_mark_seen_churn(benchmark: BenchmarkFixture) -> None: | ||
| """Benchmark sustained eviction (every call past the cap drops oldest).""" | ||
| keys = [f"churn-{i}" for i in range(_MAX_SEEN_LOGS * 4)] | ||
|
|
||
| @benchmark | ||
| def _churn() -> None: | ||
| seen: dict[str, None] = {} | ||
| for k in keys: | ||
| _mark_seen(seen, k) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.