Skip to content

Improvement: githubAnalyzer in-memory cache grows unbounded (memory leak) #38

Description

@ChitkulLakshya

Improvement: githubAnalyzer cache grows unbounded (memory leak on 512MB plan)

File: server/utils/githubAnalyzer.js:36

Problem

The in-memory cache githubCache is a Map that grows without bound:

const githubCache = new Map();

Entries are only evicted when accessed and found expired (lazy eviction in getCached). If many unique usernames are analyzed and never re-accessed, the cache grows indefinitely.

Each cached entry stores up to 30 simplified repo objects (~2-5KB per username). After 1000 unique usernames: ~5MB. After 10,000: ~50MB.

Impact on 512MB Render plan

With the lazy-load optimization from Phase 6 (server starts at ~113MB), a 50MB cache leak would bring total to ~163MB — still within limits, but concerning for long-running instances.

Fix

  1. Simple: Add a max size check in setCached:
function setCached(key, data) {
  if (githubCache.size > 500) {
    // Evict oldest entries
    const firstKey = githubCache.keys().next().value;
    githubCache.delete(firstKey);
  }
  githubCache.set(key, { data, timestamp: Date.now() });
}
  1. Better: Use an LRU cache library like lru-cache with a size limit and TTL.

  2. Best: Move cache to Redis (if available) or MongoDB for persistence across restarts.

Severity

Low-Medium — Slow leak. Won't cause immediate issues but could accumulate over weeks of uptime.

Phase

Introduced in Phase 3 (PR #28, merged).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions