Skip to content

speedup directory traversal on windows #131972

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

Merged
merged 3 commits into from
Oct 21, 2024
Merged

Conversation

klensy
Copy link
Contributor

@klensy klensy commented Oct 20, 2024

Optimizes walking over dirs on windows by replacing FindFirstFileW with FindFirstFileExW with FindExInfoBasic option, that allows skipping filling unused struct field which should be faster.

Also adds the same change for fallback call of FindFirstFileExW in metadata call.

Locally shows small speedup, but bench results from other users are welcome.

@rustbot
Copy link
Collaborator

rustbot commented Oct 20, 2024

r? @ChrisDenton

rustbot has assigned @ChrisDenton.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 20, 2024
@klensy
Copy link
Contributor Author

klensy commented Oct 20, 2024

For app:

use walkdir::WalkDir;

fn main() {
    let mut c = 0;
    for _entry in WalkDir::new(".") {
        c += 1;
    }
    
    println!("{}",c );
}

running over llvm-project folder on HDD.
dirwalk.old: rustc 1.84.0-nightly (da93539 2024-10-19) (i'll try master checkout later, maybe something other affecting perf the same as master)
dirwalk.new: this PR

$ hyperfine --warmup 3 'dirwalk.old.exe'  'dirwalk.new.exe'
Benchmark 1: dirwalk.old.exe
  Time (mean ± σ):     549.3 ms ±   6.6 ms    [User: 147.5 ms, System: 395.9 ms]
  Range (min … max):   532.9 ms … 559.6 ms    10 runs

Benchmark 2: dirwalk.new.exe
  Time (mean ± σ):     453.7 ms ±   7.2 ms    [User: 186.6 ms, System: 263.1 ms]
  Range (min … max):   441.7 ms … 460.3 ms    10 runs

Summary
  dirwalk.new.exe ran
    1.21 ± 0.02 times faster than dirwalk.old.exe

Well, idk why results difference so big, this looks wrong. Messed up source file, all ok.

Copy link
Member

@ChrisDenton ChrisDenton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me. It would be interesting to see the effect of FIND_FIRST_EX_LARGE_FETCH given modern systems. But in any case I do think this is an improvement.

@ChrisDenton
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 21, 2024

📌 Commit 2920ed0 has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 21, 2024
@bors
Copy link
Collaborator

bors commented Oct 21, 2024

⌛ Testing commit 2920ed0 with merge 3ec4308...

@bors
Copy link
Collaborator

bors commented Oct 21, 2024

☀️ Test successful - checks-actions
Approved by: ChrisDenton
Pushing 3ec4308 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 21, 2024
@bors bors merged commit 3ec4308 into rust-lang:master Oct 21, 2024
7 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 21, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3ec4308): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (secondary -2.9%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-3.7%, -2.1%] 2
All ❌✅ (primary) - - 0

Cycles

Results (secondary 4.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.8% [6.6%, 8.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-7.0% [-7.0%, -7.0%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 782.557s -> 781.937s (-0.08%)
Artifact size: 333.66 MiB -> 333.66 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. O-windows Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants