Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huonw opened this issue Aug 4, 2014 · 4 comments
Closed

Comments

@huonw
Copy link
Member

huonw commented Aug 4, 2014

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

@huonw
Copy link
Member Author

huonw commented Aug 4, 2014

cc #16236

cc @alexcrichton

@aturon
Copy link
Member

aturon commented Aug 4, 2014

cc me

@lucy
Copy link
Contributor

lucy commented Aug 4, 2014

Linux readdir doesn't return the file type on all file systems, according to readdir(3).

@alexcrichton
Copy link
Member

This has now been exposed in terms of the yielded value from the ReadDir iterator, we should be free to add various accessors in the future if necessary.

bors added a commit to rust-lang-ci/rust that referenced this issue Jan 8, 2024
internal: Remove unnecessary `Arc` allocations in `macro_expand`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants