authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-10-05 16:05:02-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-10-05 16:05:02-07:00
log39f192d54eba99ba3dfc7066476912633e694d51
treeca8f102cbcac4bd7c9a21207f0eae8db3135e9bb
parent274d19575ea1ebaea593cdca7c5afa8303153cb4

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 files changed, 5 insertions(+), 5 deletions(-)

lib/std/fs.zig+5-5
......@@ -301,7 +301,7 @@ pub const IterableDir = struct {
301301 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris => struct {
302302 dir: Dir,
303303 seek: i64,
304 buf: [8192]u8, // TODO align(@alignOf(os.system.dirent)),
304 buf: [1024]u8, // TODO align(@alignOf(os.system.dirent)),
305305 index: usize,
306306 end_index: usize,
307307 first_iter: bool,
......@@ -499,7 +499,7 @@ pub const IterableDir = struct {
499499 },
500500 .haiku => struct {
501501 dir: Dir,
502 buf: [8192]u8, // TODO align(@alignOf(os.dirent64)),
502 buf: [1024]u8, // TODO align(@alignOf(os.dirent64)),
503503 index: usize,
504504 end_index: usize,
505505 first_iter: bool,
......@@ -594,7 +594,7 @@ pub const IterableDir = struct {
594594 dir: Dir,
595595 // The if guard is solely there to prevent compile errors from missing `linux.dirent64`
596596 // definition when compiling for other OSes. It doesn't do anything when compiling for Linux.
597 buf: [8192]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(linux.dirent64)),
597 buf: [1024]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(linux.dirent64)),
598598 index: usize,
599599 end_index: usize,
600600 first_iter: bool,
......@@ -676,7 +676,7 @@ pub const IterableDir = struct {
676676 },
677677 .windows => struct {
678678 dir: Dir,
679 buf: [8192]u8 align(@alignOf(os.windows.FILE_BOTH_DIR_INFORMATION)),
679 buf: [1024]u8 align(@alignOf(os.windows.FILE_BOTH_DIR_INFORMATION)),
680680 index: usize,
681681 end_index: usize,
682682 first_iter: bool,
......@@ -754,7 +754,7 @@ pub const IterableDir = struct {
754754 },
755755 .wasi => struct {
756756 dir: Dir,
757 buf: [8192]u8, // TODO align(@alignOf(os.wasi.dirent_t)),
757 buf: [1024]u8, // TODO align(@alignOf(os.wasi.dirent_t)),
758758 cookie: u64,
759759 index: usize,
760760 end_index: usize,