A tool for analyzing the size of compiled Go binaries, offering cross-platform support, detailed breakdowns, and multiple output formats.
AGPL-3.0 License
English | 简体中文
A simple tool to analyze the size of a Go compiled binary.
ELF
, Mach-O
, and PE
binary formatstext
, json
, html
, svg
json
and text
output)Using Homebrew
brew install go-size-analyzer
Using scoop
scoop install go-size-analyzer
go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
$ gsa --web golang-compiled-binary
Will start a web server on port 8080, you can view the result in your browser.
Or you can use the WebAssembly version in the browser: GSA Treemap
[!NOTE] Due to the limitation of the browser, the WebAssembly version is much slower than the native version. Normally costs 10x time to analyze the same binary.
Only recommended for analysing small applications (less than 30 MB in size)
The web page will look like this:
You can click to expand the package to see the details.
$ gsa --tui golang-compiled-binary
$ gsa docker-compose-linux-x86_64
┌─────────────────────────────────────────────────────────────────────────────────┐
│ docker-compose-linux-x86_64 │
├─────────┬──────────────────────────────────────────────────┬────────┬───────────┤
│ PERCENT │ NAME │ SIZE │ TYPE │
├─────────┼──────────────────────────────────────────────────┼────────┼───────────┤
│ 17.37% │ k8s.io/api │ 11 MB │ vendor │
│ 15.52% │ .rodata │ 9.8 MB │ section │
│ 8.92% │ .gopclntab │ 5.6 MB │ section │
│ 7.51% │ .strtab │ 4.7 MB │ section │
│ 5.13% │ k8s.io/client-go │ 3.2 MB │ vendor │
│ 3.36% │ .symtab │ 2.1 MB │ section │
│ 3.29% │ github.com/moby/buildkit │ 2.1 MB │ vendor │
│ 2.02% │ google.golang.org/protobuf │ 1.3 MB │ vendor │
│ 1.96% │ github.com/google/gnostic-models │ 1.2 MB │ vendor │
│ 1.82% │ k8s.io/apimachinery │ 1.1 MB │ vendor │
│ 1.73% │ net │ 1.1 MB │ std │
│ 1.72% │ github.com/aws/aws-sdk-go-v2 │ 1.1 MB │ vendor │
│ 1.57% │ crypto │ 991 kB │ std │
│ 1.53% │ github.com/docker/compose/v2 │ 964 kB │ vendor │
│ 1.48% │ github.com/gogo/protobuf │ 931 kB │ vendor │
│ 1.40% │ runtime │ 884 kB │ std │
│ 1.32% │ go.opentelemetry.io/otel │ 833 kB │ vendor │
│ 1.28% │ .text │ 809 kB │ section │
│ 1.18% │ google.golang.org/grpc │ 742 kB │ vendor │
...[Collapsed]...
│ 0.00% │ github.com/google/shlex │ 0 B │ vendor │
│ 0.00% │ github.com/pmezard/go-difflib │ 0 B │ vendor │
│ 0.00% │ go.uber.org/mock │ 0 B │ vendor │
│ 0.00% │ github.com/kballard/go-shellquote │ 0 B │ vendor │
│ 0.00% │ tags.cncf.io/container-device-interface │ 0 B │ vendor │
│ 0.00% │ github.com/josharian/intern │ 0 B │ vendor │
│ 0.00% │ github.com/shibumi/go-pathspec │ 0 B │ vendor │
│ 0.00% │ dario.cat/mergo │ 0 B │ vendor │
│ 0.00% │ github.com/mattn/go-colorable │ 0 B │ vendor │
│ 0.00% │ github.com/secure-systems-lab/go-securesystemslib│ 0 B │ vendor │
├─────────┼──────────────────────────────────────────────────┼────────┼───────────┤
│ 100% │ KNOWN │ 63 MB │ │
│ 100% │ TOTAL │ 63 MB │ │
└─────────┴──────────────────────────────────────────────────┴────────┴───────────┘
$ gsa bin-linux-1.21-amd64 bin-linux-1.22-amd64
┌────────────────────────────────────────────────────────────────┐
│ Diff between bin-linux-1.21-amd64 and bin-linux-1.22-amd64 │
├─────────┬──────────────────────┬──────────┬──────────┬─────────┤
│ PERCENT │ NAME │ OLD SIZE │ NEW SIZE │ DIFF │
├─────────┼──────────────────────┼──────────┼──────────┼─────────┤
│ +28.69% │ runtime │ 801 kB │ 1.0 MB │ +230 kB │
│ +100% │ internal/chacha8rand │ │ 3.1 kB │ +3.1 kB │
│ +5.70% │ <autogenerated> │ 18 kB │ 19 kB │ +1.0 kB │
│ +8.59% │ internal/abi │ 6.1 kB │ 6.6 kB │ +525 B │
│ +10.52% │ internal/cpu │ 4.9 kB │ 5.4 kB │ +515 B │
│ +4.45% │ internal/reflectlite │ 3.9 kB │ 4.1 kB │ +173 B │
│ +2.64% │ internal/bytealg │ 1.5 kB │ 1.5 kB │ +39 B │
│ +0.80% │ strconv │ 4.0 kB │ 4.0 kB │ +32 B │
│ +0.19% │ syscall │ 13 kB │ 13 kB │ +24 B │
│ -0.37% │ embed │ 8.6 kB │ 8.6 kB │ -32 B │
│ -0.16% │ main │ 19 kB │ 19 kB │ -32 B │
│ -0.38% │ reflect │ 25 kB │ 25 kB │ -96 B │
│ -0.26% │ time │ 87 kB │ 87 kB │ -224 B │
│ -7.95% │ sync │ 9.5 kB │ 8.7 kB │ -755 B │
├─────────┼──────────────────────┼──────────┼──────────┼─────────┤
│ +8.47% │ .rodata │ 122 kB │ 132 kB │ +10 kB │
│ +5.04% │ .gopclntab │ 144 kB │ 152 kB │ +7.3 kB │
│ +3.61% │ .debug_info │ 168 kB │ 174 kB │ +6.1 kB │
│ +3.52% │ .debug_loc │ 81 kB │ 84 kB │ +2.9 kB │
│ +3.03% │ .debug_line │ 80 kB │ 82 kB │ +2.4 kB │
│ +3.41% │ .symtab │ 59 kB │ 61 kB │ +2.0 kB │
│ +4.29% │ .debug_frame │ 29 kB │ 30 kB │ +1.2 kB │
│ +1.25% │ .strtab │ 61 kB │ 62 kB │ +763 B │
│ +3.28% │ .debug_ranges │ 13 kB │ 13 kB │ +415 B │
│ +5.13% │ .data │ 5.0 kB │ 5.2 kB │ +256 B │
│ +7.32% │ .typelink │ 1.3 kB │ 1.3 kB │ +92 B │
│ +27.78% │ .go.buildinfo │ 288 B │ 368 B │ +80 B │
│ -1.56% │ .debug_gdb_scripts │ 64 B │ 63 B │ -1 B │
│ -0.63% │ .noptrdata │ 2.5 kB │ 2.5 kB │ -16 B │
├─────────┼──────────────────────┼──────────┼──────────┼─────────┤
│ +3.86% │ bin-linux-1.21-amd64 │ 1.6 MB │ 1.6 MB │ +61 kB │
│ │ bin-linux-1.22-amd64 │ │ │ │
└─────────┴──────────────────────┴──────────┴──────────┴─────────┘
$ gsa cockroach-darwin-amd64 -f svg -o data.svg --hide-sections
Usage:
gsa <file> [flags]
gsa <old file> <new file> [flags]
A tool for determining the extent to which dependencies contribute to the
bloated size of compiled Go binaries.
Arguments:
<file> Binary file to analyze or result json file for diff
[<diff file>] New binary file or result json file to compare, optional
Flags:
-h, --help Show context-sensitive help.
--verbose Verbose output
-f, --format="text" Output format, possible values: text,json,html,svg
--no-disasm Skip disassembly pass
--no-symbol Skip symbol pass
--no-dwarf Skip dwarf pass
-o, --output=STRING Write to file
--version Show version
Text output options
--hide-sections Hide sections
--hide-main Hide main package
--hide-std Hide standard library
Json output options
--indent=INDENT Indentation for json output
--compact Hide function details, replacement with size
Svg output options
--width=1028 Width of the svg treemap
--height=640 Height of the svg treemap
--margin-box=4 Margin between boxes
--padding-box=4 Padding between box border and content
--padding-root=32 Padding around root content
Web interface options
--web use web interface to explore the details
--listen=":8080" listen address
--open Open browser
Terminal interface options
--tui use terminal interface to explore the details
[!CAUTION]
The tool can work with stripped binaries, but it may lead to inaccurate results.
Any contribution is welcome, feel free to open an issue or a pull request.
For development, see the Development Guide for more details.
Published under the AGPL-3.0.