Home

Awesome

🔍 Go binary size SVG treemap

Make treemap breakdown of Go executable binary

Go Reference codecov Go Report Card go-recipes OpenSSF Scorecard

$ go install github.com/nikolaydubina/go-binsize-treemap@latest
$ go tool nm -size <binary finename> | go-binsize-treemap > binsize.svg

Disclaimer

Should you be worried about executable binary size? In 2022, few seconds of cat videos or even a single image is tens of MBs. Transferring them over network is not a big deal either. So, probably, you should not worry too much about it. However, this tool can still be useful in couple of cases.

I build this in my spare time as another usecase for Go treemap tooling that I built before. Enjoy! Submit issues or PRs!

Examples

<b><p align="center">github.com/gohugoio/hugo</p></b> <p align="center">62MB, this famous example of large Go project</p>

<b><p align="center">github.com/cockroachdb/cockroach</p></b> <p align="center">71MB, this famous db is building with C++</p>

<b><p align="center">github.com/goccy/go-graphviz</p></b> <p align="center">6.5MB, this project has CGO and builds with lots of graphviz code in C</p>

<b><p align="center">github.com/zalando/skipper</p></b> <p align="center">36MB, is a large Go project, some builds can include C</p>

Knowledge Base

What is go.itab?

This is interface related code. Refer to this article by Russ Cox.

What is runtime.pclntab? And why it is so big?

As investigated Cockroach team, it is Go runtime structure for traces (reference). Past discussions in GitHub thread on why it is big and what to do about it (well, nothing).

Known Issues and TODOs

Related Work

Reference

Appendix A: Strange Output / C++ / CGO

You many need to demungle symtab file first. Install c++flit. Then process symtab first. Note, c++ support is work in progress.

$ go tool nm -size <binary finename> | c++filt | go-binsize-treemap > binsize.svg

Appendix B: Large dimensions and lots of details

If you set dimensions very large you can see lots of details and navigate map.

4096x4096 is recommended

... but you can go much higher

Appendix C: Small dimensions and informative preview

You can generate small preview of project that fits for embedding in README for example.

1024x256 is recommended

Docs

$ cat testdata/go-graphviz.symtab | ./go-binsize-treemap  -csv > docs/go-graphviz.csv
$ cat testdata/go-graphviz.symtab | ./go-binsize-treemap > docs/go-graphviz.svg
$ cat testdata/go-graphviz.symtab | ./go-binsize-treemap -w 4096 -h 4096 > docs/go-graphviz-4096x4096.svg
$ cat testdata/cockroach.symtab | ./go-binsize-treemap -csv > docs/cockroach.csv
$ cat testdata/cockroach.symtab | ./go-binsize-treemap > docs/cockroach.svg
$ cat testdata/cockroach.symtab | ./go-binsize-treemap -w 4096 -h 4096 > docs/cockroach-4096x4096.svg
$ cat testdata/skipper.symtab | ./go-binsize-treemap > docs/skipper.svg
$ cat testdata/hugo.symtab | ./go-binsize-treemap -csv > docs/hugo.csv
$ cat testdata/hugo.symtab | ./go-binsize-treemap > docs/hugo.svg
$ cat testdata/hugo.symtab | ./go-binsize-treemap -w 1024 -h 128 > docs/hugo-1024x128.svg
$ cat testdata/hugo.symtab | ./go-binsize-treemap -w 1024 -h 256 > docs/hugo-1024x256.svg
$ cat testdata/hugo.symtab | ./go-binsize-treemap -w 1024 -h 512 > docs/hugo-1024x512.svg
$ cat testdata/hugo.symtab | ./go-binsize-treemap -w 4096 -h 4096 > docs/hugo-4096x4096.svg
$ cat testdata/hugo.symtab | ./go-binsize-treemap -w 16384 -h 16384 > docs/hugo-16384x16384.svg