いろいろ備忘録日記

主に .NET とか Go とか Flutter とか Python絡みのメモを公開しています。

Goメモ-418 (Goでコンパイルしたバイナリのサイズを分析, go-size-analyzer)

関連記事

GitHub - devlights/blog-summary: ブログ「いろいろ備忘録日記」のまとめ

概要

以下、自分用のメモです。忘れないようにここにメモメモ。。。

Goでビルドしたバイナリで、どのライブラリがどれくらい占めているのかを分析してくれるツールがあったので、忘れないうちにここにメモメモ。。

github.com

試してみた

自分のリポジトリの生成物を見てみました。

gitpod /workspace/try-golang (main) $ gsa ./try-golang
+-----------------------------------------------------------------------------+
| try-golang                                                                  |
+---------+----------------------------------------------+--------+-----------+
| PERCENT | NAME                                         | SIZE   | TYPE      |
+---------+----------------------------------------------+--------+-----------+
| 13.17%  | .gopclntab                                   | 2.1 MB | section   |
| 12.30%  | .rodata                                      | 1.9 MB | section   |
| 9.47%   | .debug_info                                  | 1.5 MB | section   |
| 6.96%   | .debug_loc                                   | 1.1 MB | section   |
| 5.59%   | .debug_line                                  | 873 kB | section   |
| 5.33%   | crypto                                       | 832 kB | std       |
| 4.97%   | github.com/devlights/try-golang              | 776 kB | vendor    |
| 4.61%   | net                                          | 719 kB | std       |
| 4.60%   | runtime                                      | 718 kB | std       |
| 3.69%   | .strtab                                      | 576 kB | section   |
| 2.35%   | .symtab                                      | 366 kB | section   |
| 2.15%   | .debug_ranges                                | 336 kB | section   |
| 1.93%   | .noptrdata                                   | 302 kB | section   |
| 1.62%   | golang.org/x/crypto                          | 252 kB | vendor    |
| 1.47%   | gopkg.in/yaml.v3                             | 229 kB | vendor    |
| 1.25%   | .debug_frame                                 | 195 kB | section   |
| 1.22%   | reflect                                      | 191 kB | std       |
| 1.10%   | text/template                                | 172 kB | std       |
| 1.06%   | encoding/gob                                 | 166 kB | std       |
| 0.97%   | github.com/pelletier/go-toml/v2              | 152 kB | vendor    |
| 0.88%   | math                                         | 137 kB | std       |
| 0.86%   | regexp                                       | 134 kB | std       |
| 0.72%   | os                                           | 112 kB | std       |
| 0.70%   | encoding/json                                | 109 kB | std       |
| 0.69%   | time                                         | 108 kB | std       |
| 0.63%   |                                              | 98 kB  | generated |
| 0.60%   | .data                                        | 94 kB  | section   |
| 0.59%   | html                                         | 92 kB  | std       |
| 0.59%   | encoding/xml                                 | 92 kB  | std       |
| 0.48%   | fmt                                          | 75 kB  | std       |
| 0.43%   | image                                        | 68 kB  | std       |
| 0.39%   | syscall                                      | 61 kB  | std       |
| 0.38%   | internal/poll                                | 59 kB  | std       |
| 0.32%   | encoding/asn1                                | 50 kB  | std       |
| 0.31%   | vendor/golang.org/x/crypto/chacha20poly1305  | 48 kB  | std       |
| 0.30%   | compress/flate                               | 46 kB  | std       |
| 0.29%   | strconv                                      | 45 kB  | std       |
| 0.26%   | slices                                       | 40 kB  | std       |
| 0.25%   | mime                                         | 39 kB  | std       |
| 0.25%   | strings                                      | 38 kB  | std       |
| 0.22%   | sync                                         | 34 kB  | std       |
| 0.21%   | vendor/golang.org/x/text/unicode/norm        | 33 kB  | std       |
| 0.21%   | internal/abi                                 | 32 kB  | std       |
| 0.20%   | github.com/devlights/gomy                    | 30 kB  | vendor    |
| 0.19%   | encoding/binary                              | 29 kB  | std       |
| 0.18%   | io                                           | 29 kB  | std       |
| 0.17%   | internal/reflectlite                         | 27 kB  | std       |
| 0.17%   | golang.org/x/text                            | 27 kB  | vendor    |
| 0.17%   | bytes                                        | 26 kB  | std       |
| 0.15%   | unicode                                      | 23 kB  | std       |
| 0.14%   | vendor/golang.org/x/net/http2/hpack          | 22 kB  | std       |
| 0.13%   | context                                      | 20 kB  | std       |
| 0.12%   | gopkg.in/natefinch/lumberjack.v2             | 19 kB  | vendor    |
| 0.12%   | vendor/golang.org/x/net/dns/dnsmessage       | 19 kB  | std       |
| 0.11%   | sort                                         | 18 kB  | std       |
| 0.11%   | github.com/shopspring/decimal                | 18 kB  | vendor    |
| 0.11%   | bufio                                        | 17 kB  | std       |
| 0.11%   | vendor/golang.org/x/crypto/cryptobyte        | 17 kB  | std       |
| 0.10%   | vendor/golang.org/x/net/idna                 | 16 kB  | std       |
| 0.10%   | path                                         | 16 kB  | std       |
| 0.09%   | flag                                         | 14 kB  | std       |
| 0.09%   | log                                          | 14 kB  | std       |
| 0.07%   | internal/bisect                              | 12 kB  | std       |
| 0.06%   | compress/gzip                                | 9.8 kB | std       |
| 0.06%   | encoding/csv                                 | 9.7 kB | std       |
| 0.06%   | text/tabwriter                               | 8.9 kB | std       |
| 0.05%   | embed                                        | 8.4 kB | std       |
| 0.05%   | vendor/golang.org/x/net/http/httpproxy       | 8.4 kB | std       |
| 0.04%   | internal/fmtsort                             | 6.6 kB | std       |
| 0.04%   | encoding/base64                              | 6.3 kB | std       |
| 0.04%   | internal/godebug                             | 6.0 kB | std       |
| 0.03%   | vendor/golang.org/x/crypto/chacha20          | 5.4 kB | std       |
| 0.03%   | container/list                               | 5.3 kB | std       |
| 0.03%   | hash/crc32                                   | 5.1 kB | std       |
| 0.03%   | vendor/golang.org/x/sys/cpu                  | 4.7 kB | std       |
| 0.03%   | errors                                       | 4.7 kB | std       |
| 0.03%   | internal/cpu                                 | 4.6 kB | std       |
| 0.03%   | .itablink                                    | 4.1 kB | section   |
| 0.03%   | encoding/hex                                 | 4.1 kB | std       |
| 0.02%   | internal/bytealg                             | 3.5 kB | std       |
| 0.02%   | encoding/pem                                 | 3.4 kB | std       |
| 0.02%   | internal/chacha8rand                         | 2.8 kB | std       |
| 0.01%   | internal/singleflight                        | 2.3 kB | std       |
| 0.01%   | golang.org/x/sys                             | 2.3 kB | vendor    |
| 0.01%   | internal/syscall/unix                        | 2.3 kB | std       |
| 0.01%   | internal/intern                              | 2.1 kB | std       |
| 0.01%   | golang.org/x/exp                             | 2.1 kB | vendor    |
| 0.01%   | container/ring                               | 2.0 kB | std       |
| 0.01%   | golang.org/x/term                            | 2.0 kB | vendor    |
| 0.01%   | vendor/golang.org/x/crypto/internal/poly1305 | 2.0 kB | std       |
| 0.01%   | vendor/golang.org/x/text/unicode/bidi        | 1.9 kB | std       |
| 0.01%   | vendor/golang.org/x/net/http/httpguts        | 1.7 kB | std       |
| 0.01%   | vendor/golang.org/x/crypto/hkdf              | 1.7 kB | std       |
| 0.01%   | golang.org/x/sync                            | 1.7 kB | vendor    |
| 0.01%   | .go.buildinfo                                | 1.4 kB | section   |
| 0.01%   | internal/testlog                             | 1.4 kB | std       |
| 0.01%   | vendor/golang.org/x/text/secure/bidirule     | 1.4 kB | std       |
| 0.01%   | .dynsym                                      | 1.0 kB | section   |
| 0.01%   | .rela.plt                                    | 888 B  | section   |
| 0.01%   | internal/saferio                             | 826 B  | std       |
| 0.00%   | .dynstr                                      | 626 B  | section   |
| 0.00%   | .plt                                         | 608 B  | section   |
| 0.00%   | internal/itoa                                | 570 B  | std       |
| 0.00%   | .shstrtab                                    | 371 B  | section   |
| 0.00%   | .got.plt                                     | 320 B  | section   |
| 0.00%   | .debug_abbrev                                | 309 B  | section   |
| 0.00%   | .dynamic                                     | 288 B  | section   |
| 0.00%   | .hash                                        | 204 B  | section   |
| 0.00%   | database/sql/driver                          | 186 B  | std       |
| 0.00%   | main                                         | 114 B  | main      |
| 0.00%   | x_cgo_munmap                                 | 112 B  | std       |
| 0.00%   | .note.go.buildid                             | 100 B  | section   |
| 0.00%   | .gnu.version_r                               | 96 B   | section   |
| 0.00%   | .gnu.version                                 | 84 B   | section   |
| 0.00%   | .debug_gdb_scripts                           | 44 B   | section   |
| 0.00%   | .interp                                      | 28 B   | section   |
| 0.00%   | .rela                                        | 24 B   | section   |
| 0.00%   | .got                                         | 8 B    | section   |
| 0.00%   | .text                                        | 1 B    | section   |
+---------+----------------------------------------------+--------+-----------+
| 99.93%  | KNOWN                                        | 16 MB  |           |
| 100%    | TOTAL                                        | 16 MB  |           |
+---------+----------------------------------------------+--------+-----------+

面白い。どうやって見てるんだろう・・・。

参考情報

Goのおすすめ書籍


過去の記事については、以下のページからご参照下さい。

サンプルコードは、以下の場所で公開しています。