Skip to content

perf(data_loader): cache JSON data in memory to avoid repeated disk reads#13

Open
Alm0stSurely wants to merge 1 commit intokomalharshita:mainfrom
Alm0stSurely:perf/cache-json-loading
Open

perf(data_loader): cache JSON data in memory to avoid repeated disk reads#13
Alm0stSurely wants to merge 1 commit intokomalharshita:mainfrom
Alm0stSurely:perf/cache-json-loading

Conversation

@Alm0stSurely
Copy link
Copy Markdown

Problem

As described in #11, utils/data_loader.py currently reads projects.json from disk on every call to load_all_projects().

Solution

Implemented in-memory cache with module-level variable:

  • _projects_cache stores data after first read
  • clear_cache() for test isolation
  • Updated tests to reset cache in setup_module()

Benchmarks

  • Cached: 0.06 µs per call
  • Uncached: 51.84 µs per call
  • Speedup: 847x

Testing

All 25 tests pass.

Fixes #11

…eads

Implements a simple module-level cache for projects.json to eliminate
repeated disk I/O on every call to load_all_projects().

Changes:
- Add _projects_cache module variable
- Modify load_all_projects() to use cache after first read
- Add clear_cache() function for test isolation
- Update tests to call clear_cache() in setup_module()
- Add benchmark script showing 847x speedup

Fixes komalharshita#11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimise data loading to avoid reading the JSON file on every request

1 participant