Skip to content

fix: Avoid recursive os.walk calls#998

Merged
gantoine merged 1 commit intorommapp:masterfrom
adamantike:fix/avoid-unneeded-recursive-os-walk
Jul 14, 2024
Merged

fix: Avoid recursive os.walk calls#998
gantoine merged 1 commit intorommapp:masterfrom
adamantike:fix/avoid-unneeded-recursive-os-walk

Conversation

@adamantike
Copy link
Contributor

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
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