Repository navigation
Conversation
| impl From<c::WIN32_FIND_DATAW> for FileAttr { | ||
| fn from(wfd: c::WIN32_FIND_DATAW) -> Self { |
There was a problem hiding this comment.
FWIW this conversion from WIN32_FIND_DATAW is still used by fs::metadata. File::metadata uses yet another conversion, from BY_HANDLE_FILE_INFORMATION. And DirEntry::metadata now uses FILE_ID_BOTH_DIR_INFO.
No idea if it makes sense to consolidate that, but I'd say that would be a job for a different PR.
|
I don't have a Windows machine so this is only build-tested so far... |
This comment has been minimized.
This comment has been minimized.
re-implement Windows ReadDir on top of GetFileInformationByHandleEx try-job: test-x86_64-msvc*
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
25e62dc to
1b5dd74
Compare
|
@bors try |
This comment has been minimized.
This comment has been minimized.
re-implement Windows ReadDir on top of GetFileInformationByHandleEx try-job: test-x86_64-msvc*
1b5dd74 to
fe876a5
Compare
|
@bors try |
re-implement Windows ReadDir on top of GetFileInformationByHandleEx try-job: test-x86_64-msvc*
This comment has been minimized.
This comment has been minimized.
| // `read_dir` on a non-directory should fail, but Windows `Dir::open` suceeds. | ||
| // So we have to specifically check for this. | ||
| return Err(io::const_error!(io::ErrorKind::NotADirectory, "path is not a directory")); | ||
| } |
There was a problem hiding this comment.
Would it maybe be better to call buf.fill() already here? Would that "naturall" throw an error for non-directories, or would we still need a dedicated check then?
Currently we delay that until the first next() call. That matches what glibc does.
There was a problem hiding this comment.
I think what you currently have is fine for now. Ideally we would be using Dir to limit it to opening a directory but, as I said, I'm uncomfortable tying this to a new unstable feature.
There was a problem hiding this comment.
I think Dir::open (open dir with just a path) will happily open files on Windows, so using Dir would not help.
Dir::open_dir (open dir relative to Dir handle) ensures that it has a directory, but that requires us to already have a Dir to begin with.
(Yeah I find that naming quite confusing... but it's what got approved in the ACP so I guess other people like it.)
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? @ChrisDenton |
|
|
This comment has been minimized.
This comment has been minimized.
fe876a5 to
a1a11c2
Compare
|
While I think this is the right long-term direction I admit I am concerned about re-implementing an important and long-stable function on top of an experimental and only partially implemented new feature. This would make |
|
Note that the only thing we do with This is on the critical path for rust-lang/miri#4982 so I'd like to find some way to make progress here. Happy to take suggestions for the best way to do that. |
|
Also, Rather than using |
a1a11c2 to
4da8841
Compare
|
I have reused the code from @bors try |
This comment has been minimized.
This comment has been minimized.
re-implement Windows ReadDir on top of GetFileInformationByHandleEx try-job: test-x86_64-msvc*
4da8841 to
436436c
Compare
97c18f3 to
9de1464
Compare
This comment has been minimized.
This comment has been minimized.
|
@bors try |
re-implement Windows ReadDir on top of GetFileInformationByHandleEx try-job: test-x86_64-msvc*
This comment has been minimized.
This comment has been minimized.
| options.read(true); | ||
| // FIXME: use race-free handle-based approach instead. | ||
| Dir::open(&self.root, &options) | ||
| dir_handle.open_dir(Path::new(""), &options) |
There was a problem hiding this comment.
Now that we have an underlying handle, we can also implement this method properly. :)
(This is only used by the unstable ReadDir::dir.)
This comment has been minimized.
This comment has been minimized.
9de1464 to
dd36e1b
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@ChrisDenton I have removed all uses of I agree this is still a big change. OTOH, if my understanding is correct, it is a change that we have to do at some point if we ever want to have If you think there is a way we can avoid this change, or a better way to stage it, I am all ears. |
|
I tested this PR on a real Windows machine (Windows 11 25H2, build 26200.9711): I built
Test programs, scripts and the exact commands: https://gist.github.com/mehmettoplu-rs/0695b793986404e20dfdd71c0d222408 I used an LLM (Claude) to help write the test programs and scripts and to run them. I decided what to test and reviewed the code, the results and the conclusions myself. If the PR changes (for example the buffer size), I can run these tests again. Environment and method
Error codesOS error codes from
PerformanceMedian time of base, and time of each variant relative to base (above 1 = slower).
I measured three rounds. The ratios varied between them (for example 16 KiB on WinSxS: 1.18x to 1.64x), but the overall pattern was the same. On WinSxS and the 100,000-file directory, 64 KiB was slower than 16 KiB in all three rounds, which I can't explain. Not tested
|
|
So tl;dr we could increase the buffer size to match the old code in performance. glibc apparently uses 32KB, but ofc performance characteristics are different between OSes. Still, that makes the 1KB on Windows look rather small. I'm happy to adjust this to 4KB or more. That will by default also affect the remove_dir_all code, though I also could introduce a const generic to let each user of the API configure their own buffer size. (Making the buffer bigger for remove_dir_all means we keep even more handles open, see #163586. Though there is also an alternative here -- the Unix version of this has a separate directory reader with separate buffer for each level of the recursion. That means we keep at most N handles open at recursion level N, but also means we have N readdir buffers rather than 1.) |
View all comments
The current implementation based on
FindFirstFileExWfundamentally relies on knowing the path to the directory, so implementingDir::read_dir(iterating a directory based on aDirhandle) is not possible.remove_dir_allalready uses a completely different implementation based onGetFileInformationByHandleExthat can work with a directory handle. This PR adjustsfs::read_dirto also use an implementation based onGetFileInformationByHandleEx.The directory entry buffer is currently 1 KiB large, as that's what we are using for
remove_dir_all. That is fairly small; it means we have to do a new syscall around every 9 entries. For comparison, the glibc implementation uses a buffer of 32 KiB by default.try-job: test-x86_64-msvc*