aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorMotiejus Jakštys <motiejus@jakstys.lt>2022-08-19 14:53:00 +0300
committerAndrew Kelley <andrew@ziglang.org>2022-10-18 12:57:21 -0400
commitfd10baf748aeb3b6d2394701d735098e64638a22 (patch)
treecf68a2365532f691b47a4e8171747474db983ef8 /src/Compilation.zig
parent5ec76cf5c84f3863618e220ce41d09cc9781af8a (diff)
downloadzig-fd10baf748aeb3b6d2394701d735098e64638a22.tar.gz
zig-fd10baf748aeb3b6d2394701d735098e64638a22.zip
os.copy_file_range: save a syscall for most operations
Currenty copy_file_range always uses at least two syscalls: 1. As many as it needs to do the initial copy (always 1 during my testing) 2. The last one is always when offset is the size of the file. The second syscall is used to detect the terminating condition. However, because we do a stat for other reasons, we know the size of the file, and we can skip the syscall. Sparse files: since copy_file_range expands holes of sparse files, I conclude that this layer was not intended to work with sparse files. In other words, this commit does not make it worse for sparse file society. Test program ------------ const std = @import("std"); pub fn main() !void { const arg1 = std.mem.span(std.os.argv[1]); const arg2 = std.mem.span(std.os.argv[2]); try std.fs.cwd().copyFile(arg1, std.fs.cwd(), arg2, .{}); } Test output (current master) ---------------------------- Observe two `copy_file_range` syscalls: one with 209 bytes, one with zero: $ zig build-exe cp.zig $ strace ./cp ./cp.zig ./cp2.zig |& grep copy_file_range copy_file_range(3, [0], 5, [0], 4294967295, 0) = 209 copy_file_range(3, [209], 5, [209], 4294967295, 0) = 0 $ Test output (this diff) ----------------------- Observe a single `copy_file_range` syscall with 209 bytes: $ /code/zig/build/zig build-exe cp.zig $ strace ./cp ./cp.zig ./cp2.zig |& grep copy_file_range copy_file_range(3, [0], 5, [0], 4294967295, 0) = 209 $
Diffstat (limited to 'src/Compilation.zig')
0 files changed, 0 insertions, 0 deletions