Skip to content

perf: use in-place cleanup for dedup and rate-limit caches (issue #192)#196

Merged
Elshayib merged 1 commit into
masterfrom
fix/issue-192-dedup-cache-cleanup
Jun 17, 2026
Merged

perf: use in-place cleanup for dedup and rate-limit caches (issue #192)#196
Elshayib merged 1 commit into
masterfrom
fix/issue-192-dedup-cache-cleanup

Conversation

@Elshayib

Copy link
Copy Markdown
Owner

Summary

Fixes #192. Replaces dict comprehension rebuilds with in-place cleanup of expired entries in both the dedup cache and rate-limit cache.

Changes

  • _is_duplicate: Instead of self._dedup_cache = {k: v for k, v in ...} (rebuilds entire dict every call), now collects expired keys into a list and deletes them in-place. Under high alert throughput this avoids O(n) dict reconstruction on every event.

  • _is_rate_limited: Added same in-place cleanup for _last_alert_time, which previously grew unbounded — every unique device key was kept forever even after the rate limit window expired.

Test Results

  • 638/638 tests passing
  • ruff clean
  • mypy clean

- _is_duplicate: replace dict comprehension rebuild with in-place deletion of expired keys
- _is_rate_limited: add same in-place cleanup for _last_alert_time (was unbounded)
- Both caches now delete only expired entries instead of reconstructing the entire dict on every call

Closes #192
@github-actions github-actions Bot added bug Something isn't working enhancement New feature or request labels Jun 17, 2026
@Elshayib Elshayib merged commit 817cab7 into master Jun 17, 2026
6 checks passed
@Elshayib Elshayib deleted the fix/issue-192-dedup-cache-cleanup branch June 17, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid rebuilding dedup cache on every alert; use TTLCache or in-place cleanup

1 participant