Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nikolaydubina/go-binsize-treemap

🔍 Go binary size SVG treemap
https://github.com/nikolaydubina/go-binsize-treemap

binary binary-analysis compiler data-visualization go golang svg symtab treemap

Last synced: about 3 hours ago
JSON representation

🔍 Go binary size SVG treemap

Awesome Lists containing this project

README

        

# 🔍 Go binary size SVG treemap

> Make treemap breakdown of Go executable binary

[![Go Reference](https://pkg.go.dev/badge/github.com/nikolaydubina/go-binsize-treemap.svg)](https://pkg.go.dev/github.com/nikolaydubina/go-binsize-treemap)
[![codecov](https://codecov.io/gh/nikolaydubina/go-binsize-treemap/branch/main/graph/badge.svg?token=jK465mG5iO)](https://codecov.io/gh/nikolaydubina/go-binsize-treemap)
[![Go Report Card](https://goreportcard.com/badge/github.com/nikolaydubina/go-binsize-treemap)](https://goreportcard.com/report/github.com/nikolaydubina/go-binsize-treemap)
[![go-recipes](https://raw.githubusercontent.com/nikolaydubina/go-recipes/main/badge.svg?raw=true)](https://github.com/nikolaydubina/go-recipes)
[![Hits](https://hits.sh/github.com/nikolaydubina/go-binsize-treemap.svg?view=today-total)](https://hits.sh/github.com/nikolaydubina/go-binsize-treemap/)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/nikolaydubina/go-binsize-treemap/badge)](https://securityscorecards.dev/viewer/?uri=github.com/nikolaydubina/go-binsize-treemap)

```
$ go install github.com/nikolaydubina/go-binsize-treemap@latest
$ go tool nm -size | 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.
- You are studying compiler.
- You are investigating what 3rd party dependencies are getting included in binary.
- You are checking much data is getting embedded.
- You are estimating how much code is getting included by packages.
- You are researching which symbols included.
- You are doing `cgo`.
- You are doing treemap visualizations.

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

## Examples

_

github.com/gohugoio/hugo

_
_

62MB, this famous example of large Go project

_
![](./docs/hugo.svg)

_

github.com/cockroachdb/cockroach

_
_

71MB, this famous db is building with C++

_
![](./docs/cockroach.svg)

_

github.com/goccy/go-graphviz

_
_

6.5MB, this project has CGO and builds with lots of graphviz code in C

_
![](./docs/go-graphviz.svg)

_

github.com/zalando/skipper

_
_

36MB, is a large Go project, some builds can include C

_
![](./docs/skipper.svg)

## Knowledge Base

> What is `go.itab`?

This is interface related code.
Refer to this [article](https://research.swtch.com/interfaces) 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](https://www.cockroachlabs.com/blog/go-file-size/)).
Past discussions in GitHub [thread](https://github.com/golang/go/issues/36313) on why it is big and what to do about it (well, nothing).

## Known Issues and TODOs

- [ ] Size slightly mismatches actual binary size. Including unknown does not help.
- [ ] Better symbol names parsing for C++
- [ ] identify go:embed
- [ ] color by type + increasing luminance (sys; user; c++; go:embed; etc.)
- [ ] color by symbol type
- [ ] heat by ????

## Related Work

- https://github.com/knz/go-binsize-viz — this was an inspiration for current tool. However, instead of Python and D3 and Javascript, this tool is using single stack purely in Go and has test coverage. Arguably, the downside it is not interactive.
- https://github.com/jondot/goweight — looks like it was working in the beginning, but as of 2022-01-22 it does not work anymore for me and there were reports dating back to 2020-01-23 for it to be not accurate.

## Reference

- https://github.com/knz/go-binsize-viz
- https://github.com/jondot/goweight
- https://github.com/nikolaydubina/treemap
- https://github.com/nikolaydubina/go-cover-treemap
- https://github.com/golang/go/blob/master/src/cmd/nm/doc.go
- https://linux.die.net/man/1/c++filt
- https://github.com/goccy/go-graphviz
- https://research.swtch.com/interfaces

## 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 | 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

![](./docs/hugo-4096x4096.svg)

... but you can go much higher
![](./docs/hugo-16384x16384.svg)

## 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/hugo-1024x256.svg)

## Docs

```bash
$ 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
```