zig
zig copied to clipboard
The file generated by running 'build' consumes more memory than 'zig build run'
Zig Version
0.12.0
Steps to Reproduce and Observed Behavior
example from github.com:zigzap/zap
const std = @import("std");
const zap = @import("zap");
fn on_request(r: zap.Request) void {
r.sendBody("Hello, World!") catch return;
}
pub fn main() !void {
var listener = zap.HttpListener.init(.{
.port = 3000,
.on_request = on_request,
.log = false,
});
try listener.listen();
std.debug.print("Listening on 0.0.0.0:3000\n", .{});
// start worker threads
zap.start(.{
.threads = 3,
.workers = 3,
});
}
run on mac m1
# step 1: run with 'zig build run', using 3MB of memory
zig build run
# step 2: run binary generated by 'zig build',using 22MB of memory
zig build
./zig-out/bin/hello
Expected Behavior
Memory usage should be consistent
What's in your build.zig?
Also, how are you measuring memory consumption? The peak RSS of the zig build run command won't include the memory usage of your application, because it's a subprocess.
In general, the "Steps to Reproduce" section should include exact steps, i.e. the precise commands / applications that were run and the relevant output to observe.