-
Notifications
You must be signed in to change notification settings - Fork 22
Test cache revival #753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test cache revival #753
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
⚡️ Codeflash found optimizations for this PR📄 252% (2.52x) speedup for
|
ce72cfd to
bbc630f
Compare
|
@KRRT7 updates on this? |
and use_cache as a test_config
…codeflash into test_cache_revival
| from codeflash.discovery.discover_unit_tests import discover_unit_tests | ||
|
|
||
| console.rule() | ||
| with progress_bar("Discovering existing function tests..."): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the progress_bar will also show the loading text animation in the extension, I think we should keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screen.Recording.2025-10-09.at.3.43.36.PM.mov
this is the artifact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screen.Recording.2025-10-09.at.3.45.08.PM.mov
no artifact
| self.cur.execute( | ||
| """ | ||
| CREATE TABLE IF NOT EXISTS discovered_tests( | ||
| project_root_path TEXT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we actually need some kind of migration engine later, for these type of changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh, that database should be empty, if not, I think only our team members would have it, but yes let me come up with a fix
The optimized code achieves a 52% speedup by replacing the traditional file reading approach with a more efficient buffered I/O pattern using `readinto()` and `memoryview`.
**Key optimizations:**
1. **Pre-allocated buffer with `readinto()`**: Instead of `f.read(8192)` which allocates a new bytes object on each iteration, the code uses a single `bytearray(8192)` buffer and reads data directly into it with `f.readinto(mv)`. This eliminates repeated memory allocations.
2. **Memory view for zero-copy slicing**: The `memoryview(buf)` allows efficient slicing (`mv[:n]`) without copying data, reducing memory overhead when updating the hash with partial buffers.
3. **Direct `open()` with unbuffered I/O**: Using `open(path, "rb", buffering=0)` instead of `Path(path).open("rb")` avoids the Path object overhead and disables Python's internal buffering to prevent double-buffering since we're managing our own buffer.
**Performance impact**: The line profiler shows the critical file opening operation dropped from 83.4% to 62.2% of total time, while the new buffer operations (`readinto`, `memoryview`) are very efficient. This optimization is particularly effective for medium to large files where the reduced memory allocation overhead compounds across multiple read operations.
**Best use cases**: This optimization excels when computing hashes for files larger than the 8KB buffer size, where the memory allocation savings become significant, and when called frequently in batch operations.
⚡️ Codeflash found optimizations for this PR📄 53% (0.53x) speedup for
|
…25-10-10T18.29.30 ⚡️ Speed up method `TestsCache.compute_file_hash` by 53% in PR #753 (`test_cache_revival`)
|
This PR is now faster! 🚀 @KRRT7 accepted my optimizations from: |
|
@mohammedahmed18 this is ready |
|
Codeflash Bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |

PR Type
Enhancement, Bug fix, Tests
Description
Add SQLite-backed tests cache with memory layer
Return replay tests count in discovery APIs
Improve robustness of pytest import error handling
Broaden path typing and hashing utilities
Diagram Walkthrough
File Walkthrough
code_utils.py
Broaden tmp file helper to accept stringscodeflash/code_utils/code_utils.py
strinput inget_run_tmp_filePathinternallydiscover_unit_tests.py
Add persistent caching and extend discovery outputscodeflash/discovery/discover_unit_tests.py
TestsCachememory/db cache and API changes