x1unix / go-playground

Better Go Playground powered by Monaco editor

Home Page:https://goplay.tools/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strip debug symbols from Wasm binaries

x1unix opened this issue · comments

Problem

Wasm binaries produced by Go compiler are pretty huge.
Sometimes they may crash browsers (Safari on iPhone) due to Wasm memory usage quota.

Solution

Add -ldflags "-s -w" build flags to strip debug info. This might save a few megabytes. This should be enough for simple applications to fit in WebKit memory quota.

Combination of -ldflags '-s -w' and -trimpath flags helped to reduce Go interpreter from 36MB to 35.3MB (2%)

According to this article, wasm-opt can help to reduce the size of WASM binary file.