#469 Performance: O(N log N) sorted() for cache eviction in activity_worker.py

closed low Created 2025-12-17 01:11 · Updated 2025-12-17 02:00

Description

Edit
engine/services/activity_worker.py:120-125 uses sorted() for LRU cache eviction. sorted() is O(N log N) when we only need the oldest K items. For large caches, this is wasteful. FIX: Use heapq.nsmallest() which is O(N log K) where K is items to evict: ```python import heapq oldest_entries = heapq.nsmallest(evict_count, cache.items(), key=lambda x: x[1][1]) ```

Comments

Loading comments...

Context

Loading context...

Audit History

View All
Loading audit history...