CacheService does expensive bookkeeping work when writing large entries or evicting under pressure.
Current behavior:
calculateEntrySize() runs JSON.stringify(entry.data) for every non-string cached value to estimate memory usage.
evictLRU() copies the whole cache into an array and sorts it on every eviction pass.
- Eviction is based on
timestamp, but normal reads do not update that timestamp, so the implementation still does not provide true LRU behavior.
Why this is inefficient:
- Large cached objects pay extra CPU and temporary memory overhead during writes.
- Eviction becomes
O(n log n) plus repeated size lookups.
- The expensive work does not buy accurate LRU semantics.
Relevant location:
src/services/cache-service.ts:328-365
Suggested direction:
- Store entry size once at insert time and reuse it on overwrite/delete/eviction.
- If LRU behavior is desired, maintain access ordering explicitly instead of sorting the full cache.
Audit source: current inefficiencies.md rank #4.
Related history:
CacheServicedoes expensive bookkeeping work when writing large entries or evicting under pressure.Current behavior:
calculateEntrySize()runsJSON.stringify(entry.data)for every non-string cached value to estimate memory usage.evictLRU()copies the whole cache into an array and sorts it on every eviction pass.timestamp, but normal reads do not update that timestamp, so the implementation still does not provide true LRU behavior.Why this is inefficient:
O(n log n)plus repeated size lookups.Relevant location:
src/services/cache-service.ts:328-365Suggested direction:
Audit source: current
inefficiencies.mdrank #4.Related history: