Skip to content

Instantly share code, notes, and snippets.

@paralin
Last active September 27, 2024 08:13
Show Gist options
  • Save paralin/57b0b6a03da3f38709c76480dce1be45 to your computer and use it in GitHub Desktop.
Save paralin/57b0b6a03da3f38709c76480dce1be45 to your computer and use it in GitHub Desktop.
Minimizing Go wasm binaries size: a multi-pronged approach

My approach to smaller Go wasm binaries:

  • protoc-gen-go-lite: Removes dependency on reflection, making your binaries lighter.
  • goweight: Analyze the size of your binaries. This is a fork with added wasm support.
  • goda: Use to find why something is imported by executing:
    goda graph "reach(.:all, gonum.org/v1/gonum/mat)" | dot -Tsvg -o graph.svg
    
  • wasm-opt: Optimize wasm binaries for size with the command:
    wasm-opt --enable-bulk-memory -Oz -o out.wasm in.wasm
    
  • brotli: Compress binaries to massively reduce size; for example, from 50MB to 3MB.
  • tinygo: Not fully compatible with all packages yet but shows promise for further size reduction.

Finally, here is a project template which incorporates all of the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment