zig icon indicating copy to clipboard operation
zig copied to clipboard

Adding first newline at the end of print function increases size of WASM file extremely.

Open cngzhnp opened this issue 2 years ago • 0 comments

Zig Version

0.11.0-dev.38+b40fc7018/

Steps to Reproduce and Observed Behavior

I have a simple code block to execute into WASM environment.

const std = @import("std");

pub fn main() !void {
    const I32x4 = @Vector(4, i32);

    const v0 = I32x4{ 1, 2, 3, 4};
    const v1 = I32x4{ 5, 6, 7, 8};

    std.debug.print("v0 is: {}\n", .{v0});
    std.debug.print("v1 is: {}\n", .{v1});
}

When I compile with these options zig build -Dtarget=wasm32-wasi -Drelease-small=true, generated WASM file size is 2301 byte and executable size for x86 target is 8704 byte.

However, when I remove the newline characters from the std.debug.print function, generated WASM file size reduced to 2229 byte. Removing only 2 newline characters cause almost %3 less generated code for WASM seems an interesting behavior because x86 target size is not changed.

Expected Behavior

If generated file for x86 target is same for after my changes, it should be same as for WASI target.

cngzhnp avatar Nov 07 '22 15:11 cngzhnp