August 28th, 2024

Show HN: Shed Light on Your Go Binary Bloat with Go Size Analyzer

The go-size-analyzer is a GitHub tool for analyzing compiled Go binaries, offering detailed size breakdowns, multiple output formats, and both web and terminal interfaces. It encourages contributions and is AGPL-3.0 licensed.

Read original articleLink Icon
Show HN: Shed Light on Your Go Binary Bloat with Go Size Analyzer

The go-size-analyzer is a GitHub repository tool designed for analyzing the size of compiled Go binaries. It supports various binary formats, including ELF, Mach-O, and PE, and provides a detailed breakdown of size contributions from different packages and sections. Users can output results in multiple formats such as text, JSON, HTML, and SVG. The tool features both a web interface and a terminal UI for interactive exploration of binary sizes, as well as a binary comparison function to identify size differences between two binaries. Installation options include downloading the latest binary from the releases page, using Homebrew for MacOS/Linux, Scoop for Windows, or installing via Go. Usage examples demonstrate different modes, including web mode for browser viewing, terminal UI, text mode, diff mode for comparing binaries, and SVG mode for graphical output. The tool can analyze stripped binaries, although this may affect accuracy. Contributions to the project are encouraged, and a development guide is available. The project is licensed under AGPL-3.0.

- The tool analyzes the size of compiled Go binaries across multiple formats.

- It offers detailed size breakdowns and supports various output formats.

- Users can interact with the tool through a web interface or terminal UI.

- Installation is straightforward with multiple options available.

- Contributions to the project are welcomed, and it is licensed under AGPL-3.0.

Link Icon 6 comments
By @peterldowns - 5 months
This is great — I dragged a binary to the demo URL and it made me realize I had forgotten to pass `-ldflags="-s -w"` to strip the DWARF and symbol tables when I was building the binary. This will take my binaries from 25 MB down to 18 MB, a ~30% reduction in space. The container I'm building drops from 45 MB down to 36 MB, a 20% reduction. Every little bit helps when it comes to deploy times and space/speed savings!

(for the container image size analysis I used dive, available here https://github.com/wagoodman/dive)

By @koito17 - 5 months
First, great tool! The README makes me want to try it immediately.

I love how the Kubernetes client for Go is always the culprit for adding dozens of megabytes to binary sizes. Thankfully, its impact on binary size is decreasing as the codebase adopts generics.

Out of curiosity, how well does this work with stripped binaries? Many people interested in reducing binary size will often strip debug symbols and add "-a -s" to LDFLAGS, so what identifying information of a package is left in a binary? Besides VCS information (unless the binary was also built with -buildvcs=false so Git commit hashes aren't baked into the binary).

By @neonsunset - 5 months
Thanks! This looks really nice and handy. I wish it could work with any native binary but I understand that it focuses on Go specifically.

On Windows, there's SizeBench[0] but it doesn't work on macOS and non-PE files, and I miss having a tool like that.

[0]: https://github.com/microsoft/SizeBench, likely used to be an internal tool that was open-sourced

By @tslocum - 5 months
I have been using this for a while to reduce the size of boxcars[0]. While the web UI is awesome, I recommend the TUI mode instead (gsa --tui <binary>), as I find it much easier to use and understand.

0. https://code.rocket9labs.com/tslocum/boxcars

By @JackYoustra - 5 months
Nice! I have something similar that works for other binary types too, try it out! https://www.jackyoustra.com/binary