Git Product home page Git Product logo

go-binsize-treemap's Introduction

๐Ÿ” Go binary size SVG treemap

Make treemap breakdown of Go executable binary

Go Reference codecov Go Report Card go-recipes

$ 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.

  • 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

github.com/cockroachdb/cockroach

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

github.com/goccy/go-graphviz

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

github.com/zalando/skipper

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

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

  • 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

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

go-binsize-treemap's People

Contributors

nikolaydubina avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.