⚡ Optimize string search by caching target files in memory - #56
⚡ Optimize string search by caching target files in memory#56himadriganguly wants to merge 1 commit into
Conversation
Cache file lines in a set so we don't have to repeatedly re-read the file. Co-authored-by: himadriganguly <5839433+himadriganguly@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What
Optimized the string search inside
SearchPattern.__checkIfStringInFileby caching the lines of comparison files into an instance-level cache (self._file_cache), where each file's contents are stored as asetof its constituent lines.🎯 Why
The previous logic opened, read, and split the contents of each file block by block every single time it checked a string pattern. For thousands of patterns checked across multiple files, this resulted in thousands of repetitive and slow disk I/O reads. Not to mention, reading the files block by block and doing a
.splitlines()would occasionally cut lines in half at block boundaries, producing arbitrary false negatives. Using asetbrings the lookups from O(N) to O(1) in memory instead of on disk.📊 Measured Improvement
I wrote a benchmarking script simulating scanning 1,000 target lines across 100 generated temporary files (where each file contained 200 lines).
PR created automatically by Jules for task 13766893227435862388 started by @himadriganguly