Description
According to http://legacy.python.org/dev/peps/pep-0471/
[...] -- it executes the stat() system call or GetFileAttributes() on each file to determine whether the entry is a directory or not.
But the underlying system calls -- FindFirstFile / FindNextFile on Windows and readdir on POSIX systems -- already tell you whether the files returned are directories or not, so no further system calls are needed. Further, the Windows system calls return all the information for a stat_result object on the directory entry, such as file size and last modification time.
Our current readdir
just returns the raw Path
s, discarding this information.
Reusing that information would likely allow us to see speed-ups for walk_dir
similar to those seen in that PEP:
In practice, removing all those extra system calls makes os.walk() about 8-9 times as fast on Windows, and about 2-3 times as fast on POSIX systems