Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/metricsAnalyzer/metricsAnalyzerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines 118 to 122
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LRU behavior is implemented by delete+set on cache hit, but there isn’t a test that verifies LRU eviction semantics (i.e., a recently-accessed entry should survive an eviction while the true least-recently-used entry is evicted). Please add a unit test that fills the cache, re-accesses one key to promote it, then inserts one more entry and asserts the promoted key is still cached (e.g., via reference equality) while the oldest non-promoted key is recomputed.

Copilot uses AI. Check for mistakes.
}
const results = analyzer(sourceText);
Expand All @@ -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. */
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache key generation includes sourceText.length in addition to language + hash, but the cache JSDoc says it’s keyed only by language + content hash. Please update the comment to match the actual key components (or remove the length component if it’s not needed).

Suggested change
/** Cache of analysis results keyed by language + content hash. Evicts least-recently-used entry when full. */
/** Cache of analysis results keyed by language + source text length + content hash. Evicts least-recently-used entry when full. */

Copilot uses AI. Check for mistakes.
const analysisCache = new Map<string, UnifiedFunctionMetrics[]>();

/** Fast non-cryptographic hash for cache key generation (djb2 variant). */
Expand Down
Loading