Repository navigation
Improve performance of os.walk() #119169
Copy link
Copy link
Open
Labels
performancePerformance or resource usagePerformance or resource usage
Description
Activity
- addedperformancePerformance or resource usagePerformance or resource usage
on May 19, 2024 In bottom-up mode, we can handle exceptions from
entry.is_symlink()in the same block as those fromentry.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 asdirs.- added 5 commits that reference this issue
on May 19, 2024 - added a commit that references this issue
on May 29, 2024 There are too many open PRs. Are they independent? Alternative? What should I review?
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usage
Projects
- StatusShow more project fieldsTodo
There are a couple of minor performance improvements possible in
os.walk():os.scandiriterator, given we handle exceptions fromnext()like exceptions fromscandir()itself, i.e. by ignoring the problematic directory and moving on. We can use aforloop like filthy casuals.In bottom-up mode, we can handle exceptions fromentry.is_symlink()in the same block as those fromentry.is_dir(), which avoids a few temporary variables.os.path.join()once on a parent directory rather than for each child path.Linked PRs
os.walk(topdown=False)#119186os.[f]walk(topdown=False)#119473pathlib.Path.walk()usingos.walk()#119573pathlib.Path.walk()usingos.walk()(GH-119573) #119750os.walk(topdown=True)#121431os.fwalk()exception handling #121432os.fwalk(topdown=False)#121433os.walk()exception handling #121435