python / cpython

The Python programming language
https://www.python.org/
Other
60.75k stars 29.33k forks source link

Improve performance of `os.walk()` #119169

Open barneygale opened 1 month ago

barneygale commented 1 month ago

There are a couple of minor performance improvements possible in os.walk():

Linked PRs

barneygale commented 1 month ago

In bottom-up mode, we can handle exceptions from entry.is_symlink() in the same block as those from entry.is_dir(), which avoids a few temporary variables.

Upon closer inspection, I think I was wrong. Symlinks to directories where is_symlink() raises should still be categorised as dirs.