Commit 39f192d54e

Ryan Liptak <squeek502@hotmail.com>
2022-10-06 01:05:02
fs: Reduce IterableDir.Iterator `buf` size to 1024
This was sized large so that `getdents` (and other platforms' equivalents) could provide large amounts of entries per syscall, but some benchmarking seems to indicate that the larger 8192 sizing doesn't actually lead to performance gains outside of edge cases like extremely large amounts of entries within a single directory (e.g. 25,000 files in one directory), and even then the gains are minimal ('./walk-8192 dir-with-tons-of-entries' ran 1.02 ± 0.34 times faster than './walk-1024 dir-with-tons-of-entries'). Note: Sizes 1024 and 2048 had similar performance characteristics, so the smaller of the two was chosen.
1 parent 274d195
Changed files (1)
lib
std
lib/std/fs.zig
@@ -301,7 +301,7 @@ pub const IterableDir = struct {
         .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris => struct {
             dir: Dir,
             seek: i64,
-            buf: [8192]u8, // TODO align(@alignOf(os.system.dirent)),
+            buf: [1024]u8, // TODO align(@alignOf(os.system.dirent)),
             index: usize,
             end_index: usize,
             first_iter: bool,
@@ -499,7 +499,7 @@ pub const IterableDir = struct {
         },
         .haiku => struct {
             dir: Dir,
-            buf: [8192]u8, // TODO align(@alignOf(os.dirent64)),
+            buf: [1024]u8, // TODO align(@alignOf(os.dirent64)),
             index: usize,
             end_index: usize,
             first_iter: bool,
@@ -594,7 +594,7 @@ pub const IterableDir = struct {
             dir: Dir,
             // The if guard is solely there to prevent compile errors from missing `linux.dirent64`
             // definition when compiling for other OSes. It doesn't do anything when compiling for Linux.
-            buf: [8192]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(linux.dirent64)),
+            buf: [1024]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(linux.dirent64)),
             index: usize,
             end_index: usize,
             first_iter: bool,
@@ -676,7 +676,7 @@ pub const IterableDir = struct {
         },
         .windows => struct {
             dir: Dir,
-            buf: [8192]u8 align(@alignOf(os.windows.FILE_BOTH_DIR_INFORMATION)),
+            buf: [1024]u8 align(@alignOf(os.windows.FILE_BOTH_DIR_INFORMATION)),
             index: usize,
             end_index: usize,
             first_iter: bool,
@@ -754,7 +754,7 @@ pub const IterableDir = struct {
         },
         .wasi => struct {
             dir: Dir,
-            buf: [8192]u8, // TODO align(@alignOf(os.wasi.dirent_t)),
+            buf: [1024]u8, // TODO align(@alignOf(os.wasi.dirent_t)),
             cookie: u64,
             index: usize,
             end_index: usize,