From 326fa548fff6e31653e7522efb6e310dec945ca5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 Apr 2026 22:13:27 +0000 Subject: [PATCH] perf: upgrade analysis cache from FIFO to LRU eviction When a cache entry is hit, delete and re-insert it so it moves to the back of the Map's insertion-order. This means the entry deleted on eviction is always the least-recently-used rather than the first inserted, which better retains hot files (e.g. the file a developer is currently editing) across larger workspaces. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/metricsAnalyzer/metricsAnalyzerFactory.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/metricsAnalyzer/metricsAnalyzerFactory.ts b/src/metricsAnalyzer/metricsAnalyzerFactory.ts index 51b2662..907d619 100644 --- a/src/metricsAnalyzer/metricsAnalyzerFactory.ts +++ b/src/metricsAnalyzer/metricsAnalyzerFactory.ts @@ -116,6 +116,9 @@ export class MetricsAnalyzerFactory { const cacheKey = `${languageId}:${sourceText.length}:${hashString(sourceText)}`; const cached = analysisCache.get(cacheKey); if (cached) { + // Move to end to maintain LRU order (most recently used stays at back) + analysisCache.delete(cacheKey); + analysisCache.set(cacheKey, cached); return cached; } const results = analyzer(sourceText); @@ -133,7 +136,7 @@ export class MetricsAnalyzerFactory { /** Maximum number of analysis results to keep in cache (one entry per unique file content). */ const CACHE_MAX_SIZE = 20; -/** Cache of analysis results keyed by language + content hash. Evicts oldest entry when full. */ +/** Cache of analysis results keyed by language + content hash. Evicts least-recently-used entry when full. */ const analysisCache = new Map(); /** Fast non-cryptographic hash for cache key generation (djb2 variant). */