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

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

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:


Zxilly
/
go-size-analyzer

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

go-size-analyzer

English | 简体中文




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

Installation

Download the latest release from the release page

Use go install is not recommended, because it won’t include the embed ui template, which is required for the web mode.

Usage

Example

Web mode

$ gsa –web golang-compiled-binary

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

The web page will look like this:

You can click to expand the package to see the details.

Text mode

$ gsa docker-compose-linux-x86_64
+——————————————————————————+
| docker-compose-linux-x86_64 |
+———+———————————————–+——–+———–+
| PERCENT | NAME | SIZE | TYPE |
+———+———————————————–+——–+———–+
| 27.76% | .gopclntab | 17 MB | section |
| 15.17% | .rodata | 9.5 MB | section |
| 11.63% | k8s.io/api | 7.3 MB | vendor |
| 6.69% | .strtab | 4.2 MB | section |
| 3.47% …

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

Leave a Reply

Your email address will not be published. Required fields are marked *