⚡ Bolt: Replace os.listdir with os.scandir for faster directory traversals - #84
⚡ Bolt: Replace os.listdir with os.scandir for faster directory traversals#84Jandir wants to merge 1 commit into
Conversation
- Refactored `scan_volumes_for_files` and `_scan_for_channel_files` in `lexis.py` to use `os.scandir()`. - Refactored `_find_legacy_databases` in `history.py` to use `os.scandir()`. - This avoids redundant `stat()` system calls during directory traversals by taking advantage of the `DirEntry` attribute caching. Co-authored-by: Jandir <3695656+Jandir@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: Replaced
os.listdirandPath.globcombined with subsequentstat()orgetsize()calls withos.scandir().🎯 Why:
os.scandirreturnsDirEntryobjects that cache file attributes like file type, size, and modification time. Usingos.listdirorglobfollowed by a call tostatorgetsizecauses the operating system to perform duplicate and expensive file system calls.📊 Impact: Measurably reduces expensive I/O operations and speeds up directory scanning (especially on networked or slow drives), improving the overall responsiveness when parsing large volumes of files.
🔬 Measurement: Verified by the passing test suite and validated via simple
timeitbenchmarks against dummy files, which showed a measurable decrease in execution time due to avoidedstat()calls.PR created automatically by Jules for task 6945930798453165538 started by @Jandir