zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 39f192d54eba99ba3dfc7066476912633e694d51 (tree)
parent 274d19575ea1ebaea593cdca7c5afa8303153cb4
Author: Ryan Liptak <squeek502@hotmail.com>
Date:   Wed,  5 Oct 2022 16:05:02 -0700

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.

Diffstat:
Mlib/std/fs.zig | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/std/fs.zig b/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,