Skip to content

⚡ Bolt: Replace os.listdir with os.scandir for faster directory traversals - #84

Open
Jandir wants to merge 1 commit into
mainfrom
bolt-os-scandir-optimization-6945930798453165538
Open

⚡ Bolt: Replace os.listdir with os.scandir for faster directory traversals#84
Jandir wants to merge 1 commit into
mainfrom
bolt-os-scandir-optimization-6945930798453165538

Conversation

@Jandir

@Jandir Jandir commented Aug 5, 2026

Copy link
Copy Markdown
Owner

💡 What: Replaced os.listdir and Path.glob combined with subsequent stat() or getsize() calls with os.scandir().

🎯 Why: os.scandir returns DirEntry objects that cache file attributes like file type, size, and modification time. Using os.listdir or glob followed by a call to stat or getsize causes 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 timeit benchmarks against dummy files, which showed a measurable decrease in execution time due to avoided stat() calls.


PR created automatically by Jules for task 6945930798453165538 started by @Jandir

- 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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant