Problem Statement
When I compiled Go code to WASM using:
bashGOOS=wasip1 GOARCH=wasm go build -o contract.wasm main.go
I found that Go-compiled WASM files are significantly larger (3–5×) and exhibit slower execution speed in runtimes like wasmer than those compiled with TinyGo for the same codebase.
Questions
-
Why is Go’s WASM binary so large?
- Upon converting the WASM files to C using
wasm2c, it was observed that Go-compiled files contain a significant number ofswitch-casestatements, along with a large amount of runtime-related functions. Do these code be the reason for the bloated WASM size and low runtime efficiency?
- Upon converting the WASM files to C using
-
How to optimize Go-Compiled Are there compiler flags to reduce WASM size/improve speed?
- Are there any compiler flags available to reduce WASM size/improve execution speed?
- Could Go’s WASM backend leverage LLVM (like TinyGo) for better optimizations?