Go: how fat are your dependencies? Use go-size-analyzer!

Christophe Colombier - Apr 25 - - Dev Community

Most project comes with dependencies.

Go is quite interesting as the compiler only ships the needed code.

Think about node, it's definitely not the same and the its node_modules folder…

Let's go back to Go, so the compiler "imports" only what is needed.

But we were facing a lack of tooling easy to understand to estimate the consequences of dependencies.

Until recently, and this wonderful project and tool:

GitHub logo Zxilly / go-size-analyzer

A tool for analyzing the size of compiled Go binaries, offering cross-platform support, detailed breakdowns, and multiple output formats.

go-size-analyzer

Go Report Card Tests Codecov GitHub release go-recipes OpenSSF Scorecard

English | 简体中文

A simple tool to analyze the size of a Go compiled binary.

  • Cross-platform support for analyzing ELF, Mach-O, and PE binary formats
  • Detailed size breakdown by packages and sections
  • Support multiple output formats: text, json, html, svg
  • Interactive exploration via web interface and terminal UI
  • Binary comparison with diff mode (supports json and text output)

Installation

Packaging status

MacOS / Linux via Homebrew:

Using Homebrew

brew install go-size-analyzer

Windows:

Using scoop

scoop install go-size-analyzer

Go Install:

go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest

Usage

Example

Web mode

$ gsa --web golang-compiled-binary
Enter fullscreen mode Exit fullscreen mode

Will start a web server on port 8080, you can view the result in your browser.

Or you can use the WebAssembly version in the browser: GSA Treemap

Note

Due to the limitation of the browser, the WebAssembly version is much slower than the native version Normally costs 10x time to analyze…

A tool for analysing the size of dependencies in compiled Golang binaries, providing insight into their impact on the final build.

Kudos @zxilly (I'm unsure you are active on Dev.to), but thanks

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .