Optimize Go binary size
~21MB
Well, I found yesterday that LogPacker Daemon weights about 21MB. This application is written in Go language, it’s really doing a lot of things, has built-in connectors to different Data-Storages, has Cluster solution inside, etc.
Some people are complaining about huge size of Go compiled binaries. But it makes sence, Go includes debugging information into binary for GDB.
|
|
~15MB
We distribute this binary to our customers, and they do not need to debug this tool, so I decided to turn off it.
Omit the DWARF symbol table during the build process:
|
|
The -s ldflag will omit the symbol table and debugging information when building your executable:
|
|
Result:
|
|
Conclusion
This optimization doesn’t affect program, so feel free to use it in production if you you don’t intend on using the debug symbols.
Feedback
As always, please reach out to me on X with questions, corrections, or ideas!