authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-06-07 22:37:53-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-06-08 02:16:15-07:00
log2f188290e203780752597b0263581590af3a69b2
treeebab0d11aa6a249ef05337725f57d868e848a75c
parent00ff65357666a7ec161d6e80c92be2ccc79e3638

Use `iterateAssumeFirstIteration` in `Walker.next` to avoid unnecessary lseek calls

Since we are opening each directory for iteration, we know that we don't need to reset the cursor's directory before iterating. Using `iterateAssumeFirstIteration` skips the cursor resetting which eliminates an `lseek` syscall for every directory opened on non-Windows platforms. This doesn't seem to actually matter much for performance (1.01 ± 0.02 times faster when walking /home/ on my system) but avoiding unnecessary syscalls is always nice anyway.

1 files changed, 1 insertions(+), 1 deletions(-)

lib/std/fs.zig+1-1
......@@ -972,7 +972,7 @@ pub const IterableDir = struct {
972972 {
973973 errdefer new_dir.close();
974974 try self.stack.append(StackItem{
975 .iter = new_dir.iterate(),
975 .iter = new_dir.iterateAssumeFirstIteration(),
976976 .dirname_len = self.name_buffer.items.len,
977977 });
978978 top = &self.stack.items[self.stack.items.len - 1];