The reason for the performance difference is likely the use of `sendfile` in the Rust implementation by way of `std::io::copy` when you do ```rust std::io::copy(&mut body.reader(), &mut stdout)?; ``` [On Linux and Android that calls `sys::kernel_copy::copy_spec`](https://doc.rust-lang.org/src/std/io/copy.rs.html#62) which has [`sendfile` optimizations](https://doc.rust-lang.org/stable/src/std/sys/unix/kernel_copy.rs.html#19). In the zig implementation you do, ``` const body = request.reader().readAllAlloc(allocator, 8192) catch unreachable; defer allocator.free(body); const stdout = std.io.getStdOut().writer(); try stdout.print("{} {s}\n", .{i, body}); ``` When you should probably be doing something like `std.os.sendfile` or something _like_ that. I don't write Zig but the patch for [`sendfile` optimizations landed there](https://ziglang.org/documentation/master/std/src/std/os/linux.zig.html). [Zig has had these optimization since 2020](https://github.com/ziglang/zig/pull/4612) The lack of `sendfile` means you made an additional double-copy, moving all the data from kernel space to user space and back. Good luck! ------ Follow up questions from me * https://stackoverflow.com/questions/77130528/does-zigs-fifo-pump-support-sendfile * https://stackoverflow.com/questions/77130539/does-zigs-http-client-allow-you-to-get-access-to-the-file-descriptor-for-the-so
The reason for the performance difference is likely the use of
sendfilein the Rust implementation by way ofstd::io::copywhen you doOn Linux and Android that calls
sys::kernel_copy::copy_specwhich hassendfileoptimizations. In the zig implementation you do,When you should probably be doing something like
std.os.sendfileor something like that. I don't write Zig but the patch forsendfileoptimizations landed there. Zig has had these optimization since 2020The lack of
sendfilemeans you made an additional double-copy, moving all the data from kernel space to user space and back.Good luck!
Follow up questions from me