Skip to content

io::readdir (apparently) has access to useful information about its child entries #16237

Closed
@huonw

Description

@huonw

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions