Replace manual cache with functools lru-cache - #1696
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors caching mechanisms across several modules in Ramble to use Python's built-in functools.lru_cache instead of custom dictionary-based caches. Specifically, it updates _ast_parse in expander.py, limits the cache size of _parse_when in language_helpers.py, and converts repository and workspace file-reading caches to static methods decorated with lru_cache. Feedback on these changes highlights a critical issue in workspace.py: converting read_file_content to a static method with a global lru_cache can lead to global cache pollution across unit tests and incorrect behavior if relative paths are resolved under different working directories. Reverting to an instance-specific cache is recommended.
Ramble Performance Test MetricsResults produced with commit: c28c192
|
This has the benefit of restricting unbounded cache growth, and improves on readability, without having the manual cache implementation cluttering the main logic.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces manual caching mechanisms with functools.lru_cache to optimize memory usage and simplify the codebase. Specifically, it updates _ast_parse in expander.py to use an LRU cache with a maximum size of 2048, limits the cache size of _parse_when in language_helpers.py to 4096, and refactors FastObjectChecker in repository.py to use a cached static method instead of a manual global dictionary cache. There are no review comments, and I have no additional feedback to provide.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1696 +/- ##
===========================================
- Coverage 93.33% 93.33% -0.01%
===========================================
Files 364 364
Lines 35481 35476 -5
===========================================
- Hits 33116 33111 -5
Misses 2365 2365 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This has the benefit of restricting unbounded cache growth, and improves on readability, without having the manual cache implementation cluttering the main logic.