Skip to content

Perf: Implement in-memory caching for Graph and Cluster JSON files 1174 - #1192

Merged
komalharshita merged 2 commits into
komalharshita:mainfrom
desireddymohithreddy0925:feat/issue-1174-in-memory-caching
Jul 18, 2026
Merged

Perf: Implement in-memory caching for Graph and Cluster JSON files 1174#1192
komalharshita merged 2 commits into
komalharshita:mainfrom
desireddymohithreddy0925:feat/issue-1174-in-memory-caching

Conversation

@desireddymohithreddy0925

Copy link
Copy Markdown

Summary

This PR addresses issue #1174 by introducing in-memory caching for the Recommender Engine's static JSON files (clusters.json and skill_graph.json). Previously, the backend executed synchronous disk I/O on every API call to read these files, creating a latency bottleneck at scale. By declaring module-level variables (_cached_clusters and _cached_skill_graph) and updating the respective load functions to serve data from memory after the initial read, we eliminate redundant disk reads entirely. A clear_caches() function is also provided to allow for explicit cache invalidation during unit testing.

Related Issue

Closes #1174

Type of Change

  • Bug fix — resolves a broken behaviour
  • Feature — adds new functionality
  • Data — adds new projects to data/projects.json
  • Documentation — updates docs, README, or code comments only
  • Style — CSS or visual changes only, no logic change
  • Refactor — restructures code without changing behaviour
  • Test — adds or updates tests

What Was Changed

File Change made
src/utils/recommender.py Declared global cache variables _cached_clusters and _cached_skill_graph alongside boolean initialization flags. Updated _load_clusters() and _load_skill_graph() to return the cached references instead of parsing the files off disk. Implemented clear_caches() to reset the global state for testing environments.

How to Test This PR

  1. Clone this branch: git checkout feat/issue-1174-in-memory-caching
  2. Install dependencies: pip install -r requirements.txt
  3. Run the app: python app.py
  4. Send a recommendation request via the frontend UI.
  5. Notice that subsequent requests are processed substantially faster since the static JSON files are already stored in memory.
  6. Run the tests: python tests/test_basic.py (or pytest tests/test_basic.py) to verify that the caching does not break any assertions.

Expected test output:

27 passed, 0 failed out of 27 tests

Test Results

============================= test session starts ==============================
platform darwin -- Python 3.x.x, pytest-x.x.x, pluggy-x.x.x
rootdir: /Users/desireddymohithreddy/GSSOC2026DevPath/DevPathMRD
collected 27 items                                                             

tests/test_basic.py ...........................                          [100%]

============================== 27 passed in 0.12s ==============================

Self-Review Checklist

  • I have read CONTRIBUTING.md and followed all guidelines
  • My branch name follows the convention: feat/, fix/, docs/, data/, style/, test/
  • I have run python tests/test_basic.py and all 27 tests pass
  • I have run flake8 . locally and there are no errors
  • I have not introduced any print() or console.log() debug statements
  • Every new function I wrote has a docstring
  • I have not modified files outside the scope of the linked issue
  • If I changed the UI, I tested it at 375px (mobile) and 1280px (desktop)
  • If I added a project to the dataset, it has all required JSON fields

Notes for Reviewer

None

@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

@komalharshita komalharshita left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks good! This PR introduces a clean in-memory caching mechanism for the graph and cluster JSON files, reducing repeated disk reads and improving performance without changing the application's behavior. The addition of cache invalidation support and successful test results further increase confidence in the implementation. Overall, this is a well-scoped performance improvement with no blocking issues.

Approved for merge. ✅

@komalharshita
komalharshita merged commit 8110f46 into komalharshita:main Jul 18, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: In-memory caching for Graph and Cluster JSON files

2 participants