Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
GH-119169: Slightly speed upos.walk(topdown=True)#121431
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
When `os.walk()` traverses into subdirectories in top-down mode, call`os.path.join()` once to add a trailing slash, and use string concatenationthereafter to generate child paths.
os.walk(topdown=True)os.walk(topdown=True)| # above. | ||
| iffollowlinksornotislink(new_path): | ||
| stack.append(new_path) | ||
| ifdirs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
How much of the gain is due to the elimination ofos.join and how much due to the check on emptydirs? On my system a walk of a folder with github repositories (including the cpython repo) hasdirs empty about 60% of the times.
b19ad11 intopython:mainUh oh!
There was an error while loading.Please reload this page.
…121431)pythonGH-119186: Slightly speed up `os.walk(topdown=True)`When `os.walk()` traverses into subdirectories in top-down mode, call`os.path.join()` once to add a trailing slash, and use string concatenationthereafter to generate child paths.
Uh oh!
There was an error while loading.Please reload this page.
When
os.walk()traverses into subdirectories in top-down mode, callos.path.join()once to add a trailing slash, and use string concatenation thereafter to generate child paths.(this trick is already used in
os.fwalk())os.walk()#119169