notes:programming:golang_filesize_optimization
Table of Contents
Go filesize optimization tricks
Let's assume that you want to use TinyGo, but can't - in my case, it was high GC pauses due to it using a simple mark/sweep GC designed for 64KB heaps, not multi-megabyte ones… What tricks can you employ to make your Go file smaller?
Developed as part of WebAssembly ZZT port research - OpenZoo/openzoo-go.
Development
- Check the size of imported packages: https://stackoverflow.com/questions/70764915/how-to-check-the-size-of-packages-linked-into-my-go-code
Compilation
- Add
-trimpath -ldflags=“-s -w”
at the end of thego build
comamnd to remove/reduce debugging information. - Replace
go build
withgarble -tiny build
to remove debugging information/stack traces even further. (Install instructions for garble [here](https://github.com/burrowers/garble).) - For WebAssembly, use
wasm-opt -Oz -o out/openzoo-go-optimized.wasm out/openzoo-go.wasm
to run a separate optimization pass on the WASM binary. - Use
-gcflags=all=“-B”
to disable bounds checking.
notes/programming/golang_filesize_optimization.txt · Last modified: 2022/10/06 20:32 by asie