/gobuildsize

Wrap go build to analyze compiled object file sizes by package

Primary LanguageGoApache License 2.0Apache-2.0

gobuildsize

Why are my Go builds using so much space? With gobuildsize you can extract package-level data on the sizes of archive files fed to the linker.

Usage

Suppose you have a regular Go build:

go build "$FLAGS"

Substitute this command with the following:

gobuildsize "$FLAGS"

This will print out byte sizes of archive files that Go compiler creates for each Go package participating in the build. For a quick example, gobuildsize can measure itself:

go build ./cmd/gobuildsize
./gobuildsize ./cmd/gobuildsize | head -n 10
runtime11772860
reflect2938266
syscall1799498
time1319664
internal/abi1180960
os1130052
fmt958316
regexp/syntax944206
regexp809204
internal/reflectlite801036

Limitations

Note that Go will aggressively eliminate unreachable package from the final executable. Therefore, if a packages shows up in the gobuildsize report it certainly contributes to the build-time resource usage and takes space in the cache, but it does not necessarily contribute to the final statically linked executable bloat. This report is therefore more about understanding slow builds and controlling resources in constrained CI environments than optimizing the size of the final executable.