from Hacker News

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

by zxilly on 8/28/24, 3:15 PM with 13 comments

I've created a powerful tool to help Go developers uncover the hidden giants in their compiled binaries. Go Size Analyzer is like an X-ray machine for your Go executables, revealing:

Which dependencies are eating up your binary size

Unexpected bloat from standard library or vendor packages

Size changes between binary versions with a visual diff

Key features that set it apart:

Interactive treemap visualizations (check out the demo: https://gsa.zxilly.dev)

Slick terminal UI for deep diving into package hierarchies

Cross-platform support (works on Linux, macOS, and Windows binaries)

Export to SVG for easy sharing and documentation or just visualize the CI process

Whether you're optimizing for edge devices, reducing Docker image sizes, or just curious about what's really inside your Go binaries, this tool provides detailed insights. .

  • by peterldowns on 8/29/24, 12:26 AM

    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 on 8/28/24, 6:25 PM

    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 on 8/28/24, 8:48 PM

    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 on 8/29/24, 12:04 AM

    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 on 8/29/24, 12:25 AM

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