Skip to content

Not fair to zig, need to use sendfile. #16

@EvanCarroll

Description

@EvanCarroll

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

std::io::copy(&mut body.reader(), &mut stdout)?;

On Linux and Android that calls sys::kernel_copy::copy_spec which has sendfile optimizations. 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. Zig has had these optimization since 2020

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions