Skip to content
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

fix: Avoid recursive os.walk calls #998

Merged

Conversation

adamantike
Copy link
Collaborator

os.walk is a generator that can iteratively navigate from the specified path, top-bottom. However, most of the calls to os.walk in the project cast the call to list(), which makes it traverse the path and recursively find all nested directories.

This is commonly not needed, as we end up just using a [0] index to only access the root path.

This change adds a few utils that simplifies listing files/directories, and by default does it non-recursively. Performance gains shouldn't be noticeable in systems with high-speed storage, but we can avoid the edge cases of users having too many nested directories, by avoiding unneeded I/O.

`os.walk` is a generator that can iteratively navigate from the
specified path, top-bottom. However, most of the calls to `os.walk` in
the project cast the call to `list()`, which makes it traverse the path
and recursively find all nested directories.

This is commonly not needed, as we end up just using a `[0]` index to
only access the root path.

This change adds a few utils that simplifies listing files/directories,
and by default does it non-recursively. Performance gains shouldn't be
noticeable in systems with high-speed storage, but we can avoid the edge
cases of users having too many nested directories, by avoiding unneeded
I/O.
@adamantike adamantike force-pushed the fix/avoid-unneeded-recursive-os-walk branch from be5b6d8 to f20a9ff Compare July 13, 2024 18:30
@gantoine gantoine merged commit 3dc4863 into rommapp:master Jul 14, 2024
3 checks passed
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.

2 participants