Go-binsize-treemap - Go binary size SVG treemap

🔍 Go binary size SVG treemap

Make treemap breakdown of Go executable binary

$ 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

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

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

Similar Resources

A tool to analyze and troubleshoot a Go binary size.

A tool to analyze and troubleshoot a Go binary size.

goweight A tool to analyze and troubleshoot a Go binary size. For more, see this blog post ✅ Get a breakdown of all modules inside a binary ✅ Supports

Dec 26, 2022

A lightweight replacement for the standard fmt package, reduces binary size by roughly 400kb in a hello world

console This is a lightweight replacement for the fmt package, reduces the binary size by roughly 400kb in a hello world program. Please note: This pa

Nov 7, 2021

searchHIBP is a golang tool that implements binary search over a hash ordered binary file.

searchHIBP is a golang tool that implements binary search over a hash ordered binary file.

Nov 9, 2021

Shotizam analyzes the size of Go binaries

Shotizam Shotizam analyzes the size of Go binaries and outputs SQL with size info for analysis in SQLite3. $ shotizam --sqlite /some/go.binary SQLite

Nov 27, 2022

Shotizam analyzes the size of Go binaries

Shotizam Shotizam analyzes the size of Go binaries and outputs SQL with size info for analysis in SQLite3. $ shotizam --sqlite /some/go.binary SQLite

Nov 27, 2022

Shotizam analyzes the size of Go binaries

Shotizam Shotizam analyzes the size of Go binaries and outputs SQL with size info for analysis in SQLite3. $ shotizam --sqlite /some/go.binary SQLite

Nov 27, 2022

A simple thread-safe, fixed size LRU written in Go. Based on dominictarr's Hashlru Algorithm. 🔃

go-hashlru A simple thread-safe, fixed size LRU written in Go. Based on dominictarr's Hashlru Algorithm. 🔃 Uses map[interface{}]interface{} to allow

Dec 5, 2022

A tool to filter URLs by parameter count or size

GoFilter A tool to filter URLs by parameter count or size. This tool requires unique sorted URL list. For example: cat hosts.txt | sort -u sorted &&

Dec 18, 2022

A Connected Graph Generator tool that construct graphs of some given size

graph graph is a Connected Graph Generator tool that construct graphs of some given size. Notice that it generates all possible connected, undirected

Nov 5, 2021

Converts a number to its English counterpart. Uses arbitrary precision; so a number of any size can be converted.

Converts a number to its English counterpart. Uses arbitrary precision; so a number of any size can be converted.

Dec 14, 2021

Removes unnecessarily saved git objects to optimize the size of the .git directory.

Git Repo Cleaner Optimizes the size of the .git directory by removing all of the files that are unnecessarily-still-saved as part of the git history.

Mar 24, 2022

This provides the lru package which implements a fixed-size thread safe LRU cache

golang-lru This provides the lru package which implements a fixed-size thread sa

Dec 22, 2021

Image size analyzer for jpg/png/gif/webp

imgsz Image size analyzer for jpg/png/gif/webp Usage // DecodeSize decodes the dimensions of an image that has // been encoded in a registered format.

Jan 8, 2022

YouTube'da altyazısı olan veya otomatik olarak oluşturulmuş altyazılı videolarda istediğiniz kelimenin hangi saat, dakika ve saniye de geçtiğini size gösterip aradığınız şeyi hızlıca bulmanızı sağlar.

YouTube Subtitles YouTube'da altyazısı olan veya otomatik olarak oluşturulmuş altyazılı videolarda istediğiniz kelimenin hangi saat, dakika ve saniye

Mar 4, 2022

2D rendering for different output (raster, pdf, svg)

2D rendering for different output (raster, pdf, svg)

draw2d Package draw2d is a go 2D vector graphics library with support for multiple outputs such as images (draw2d), pdf documents (draw2dpdf), opengl

Dec 25, 2022

Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

rasterx Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing. Pat

Nov 1, 2022

Go Language Library for SVG generation

Go Language Library for SVG generation

SVGo: A Go library for SVG generation The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification (http://www.w3.org/TR/SVG

Jan 6, 2023

Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Canvas is a common vector drawing target that can output SVG, PDF, EPS, raster images (PNG, JPG, GIF, ...), HTML Canvas through WASM, and OpenGL. It h

Dec 25, 2022
Comments
  • issue with input for some go nm

    issue with input for some go nm

    from reddit: https://old.reddit.com/r/golang/comments/scexuw/visualise_treemap_of_your_go_executable_binary/

    That's a nice tool. I think my nm is a little different from yours. I get errors like 2022/01/25 12:39:22 error parasing symtab file at line num(0): wrong size field: strconv.Atoi: parsing "409a80": invalid syntax: line: 409a80 0 t the line (line 1; the line numbering in errors is off by one) from go tool nm is one of about 30 which appear at the top of the output when I nm non-trivial programs. (go 1.17.6 on linux/amd64)

2D rendering for different output (raster, pdf, svg)
2D rendering for different output (raster, pdf, svg)

draw2d Package draw2d is a go 2D vector graphics library with support for multiple outputs such as images (draw2d), pdf documents (draw2dpdf), opengl

Dec 25, 2022
Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.
Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

rasterx Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing. Pat

Nov 1, 2022
Go Language Library for SVG generation
Go Language Library for SVG generation

SVGo: A Go library for SVG generation The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification (http://www.w3.org/TR/SVG

Jan 6, 2023
Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.
Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Canvas is a common vector drawing target that can output SVG, PDF, EPS, raster images (PNG, JPG, GIF, ...), HTML Canvas through WASM, and OpenGL. It h

Dec 25, 2022
gensvg generates SVG to an io.Writer
gensvg generates SVG to an io.Writer

gensvg: A Go library for SVG generation The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification

Dec 28, 2022
A simple API written in Go that creates badges in SVG format, based on the requested route.

A simple API written in Go that creates badges in SVG format, based on the requested route. Those graphics can be used to style README.md files, or to add tags to webpages.

Jul 2, 2021
Very simple SVG to PNG converter library using the Inkscape.

svg2png Description Very simple SVG to PNG converter library using the Inkscape.

Jan 11, 2022
Snippit - Creates syntax-highlighted code snippets in png or svg format
Snippit - Creates syntax-highlighted code snippets in png or svg format

snippit creates syntax-highlighted code snippets in png or svg format. Installat

Oct 10, 2022
Generate image plots of processes' memory usage very quickly, within a single binary.
Generate image plots of processes' memory usage very quickly, within a single binary.

memplot A small utility written in golang to quickly plot memory usage of processes. memplot constantly samples memory usage of a process, for a given

Apr 17, 2021
🎄 Go code coverage to SVG treemap

?? Go cover to Treemap Useful when you have large project with lots of files and packages $ go install github.com/nikolaydubina/go-cover-treemap@lates

Jan 9, 2023