Skip to content

Commit d36547f

Browse files
giorgidzemeta-codesync[bot]
authored andcommitted
Eliminate intermediate vector in traverse_path function
Summary: ### Summary This diff optimizes the `traverse_path` function in `traversal.rs` by eliminating the unnecessary intermediate vector `entries`. Instead of collecting the entries into a vector and then iterating over it, the code now directly iterates over the `entries` iterator, reducing memory allocation and deallocation. Reviewed By: akushner Differential Revision: D83885563 fbshipit-source-id: ec7da884bd081bde4f2f93ac8cb9cf27cfaad8d5
1 parent fc3993d commit d36547f

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

eden/fs/cli_rs/edenfs-commands/src/debug/bench/traversal.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,13 @@ impl InProgressTraversal {
179179
let read_dir_duration = start_time.elapsed();
180180

181181
let entries = read_dir_result?;
182+
let mut entry_count = 0;
182183

183-
// Count entries in this directory
184-
let entries: Vec<_> = entries.collect::<Result<Vec<_>, _>>()?;
185-
let entry_count = entries.len();
186-
187-
// Add stats for this directory
188-
self.add_read_dir_stats(read_dir_duration, entry_count);
189-
190-
for entry in entries {
184+
for entry_result in entries {
185+
let entry = entry_result?;
191186
let path = entry.path();
192187
let file_type = entry.file_type()?;
188+
entry_count += 1;
193189

194190
if file_type.is_dir() {
195191
if file_type.is_symlink() {
@@ -207,10 +203,12 @@ impl InProgressTraversal {
207203
if self.file_count < self.max_files {
208204
self.add_file(path);
209205
} else {
206+
self.add_read_dir_stats(read_dir_duration, entry_count);
210207
return Ok(());
211208
}
212209
}
213210
}
211+
self.add_read_dir_stats(read_dir_duration, entry_count);
214212
}
215213
Ok(())
216214
}

0 commit comments

Comments
 (0)