Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default project starting point generates unexpectedly large .wasm file #1418

Open
MichaelMBradley opened this issue Aug 8, 2024 · 0 comments

Comments

@MichaelMBradley
Copy link

🐛 Bug description

When building the default provided project in release mode without the console panic hook, the size of the output .wasm file is 13KB, more than I would expect for such logic and much more than the 172 byte add example.

🤔 Expected Behavior

Much smaller wasm file is generated.

👟 Steps to reproduce

Create a new project with wasm-pack new wasm.
Comment out the console_error_panic_hook feature in Cargo.toml (after which the compiler correctly points out that set_panic_hook() is never used).
Build with wasm-pack build --release.
Check code size with ls -l pkg/wasm_bg.wasm (13294 bytes).
Note: Enabling LTO and setting opt-level = "z" in Cargo.toml didn't alter the size of the generated code, and stdout indicates that wasm-opt was found and used for optimization.

Alternatively:
Replace code in src/lib.rs with the basic add example.
Compile as above, check code size (13226 bytes).

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: 0.13.0
rustc version: 1.80.0

Arch Linux 6.10.3, wasm-bindgen installed through Cargo, wasm-opt installed through system binaryen package.

I first noticed this when analyzing the code size of some basic functions I'd implemented in another project and found there was 13KB I just couldn't drop, even trying to avoid allocating memory, possible panics and string formatting. When compiling with --dev and passing the output to twiggy I see plenty of space taken up by these sorts of functions, but that hasn't been passed through wasm-opt so that may not mean anything (when I do optimize it the names provided by twiggy are meaningless to me e.g. code[0] at 4650 bytes, data[3] at 1982 bytes, etc.).

I've also included the output from cargo rustc --release -- --emit llvm-ir: llvm-ir.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant