In the Go community, the size of application binaries is always a hot topic. In the pursuit of extreme performance, every byte counts. Go is known for its simplicity and efficiency, but as projects grow in size, so can the binaries. In this article, I will show you how to use go-size-analyzer and how to interpret the results. Installation The project is hosted on GitHub. You can visit https://github.com/Zxilly/go-size-analyzer to read the full documentation. go-size-analyzer provides precompiled versions which you can download from GitHub Release. It is also available through some package managers: Homebrew (MacOS/Linux): brew install go-size-analyzer Scoop (Windows): scoop install go-size-analyzer Go Build and Install: go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest The compiled version needs to download the required resource files from GitHub at runtime. These files are embedded in the precompiled versions. Usage Run gsa --version to ensure go-size-analyzer is installed correctly. Locate the binary you want to analyze. Here, we choose the Linux x86_64 version of CockroachDB. gsa --web cockroach-linux-amd64 Wait for the command line to display: Use your browser to visit http://localhost:8080, and you will see: If this is your project, you can click on the package name on the left to see specific details. Is there a rarely used dependency taking up a lot of space? Has embed included extra files? A simpler way is to check the sections on the right. We can see that the .debug_* segments take up a lot of space. Using go tool link --help to view the specific parameters of Go's linker, we find: -s disable symbol table -strictdups int sanity check duplicate symbol contents during object file reading (1=warn 2=err). -tmpdir directory use directory for temporary files -v print link trace -w disable DWARF generation This means using the -s -w parameters can remove the .symtab and .debug_* segments, saving about 40M of space in this binary. To pass parameters to the linker during compilation, you can use the -ldflags parameter. The complete command would be go build -ldflags="-s -w". Summary In this article, we introduced how to use the go-size-analyzer tool to analyze the size of Go application binaries. This tool allows you to visualize the space occupied by different parts of your program and identify areas for optimization. We found that in many cases, the .debug_* segments take up a considerable amount of space, and using the -s -w parameters of the Go linker can significantly reduce the binary size. If you find this tool helpful, consider visiting my GitHub repository at https://github.com/Zxilly/go-size-analyzer and giving it a star. Your support is very important to me, as it not only motivates me to continue improving this tool but also helps more people discover this useful resource. In the Go community, the size of application binaries is always a hot topic. In the pursuit of extreme performance, every byte counts. Go is known for its simplicity and efficiency, but as projects grow in size, so can the binaries. In this article, I will show you how to use go-size-analyzer and how to interpret the results. go-size-analyzer Installation The project is hosted on GitHub. You can visit https://github.com/Zxilly/go-size-analyzer to read the full documentation. https://github.com/Zxilly/go-size-analyzer go-size-analyzer provides precompiled versions which you can download from GitHub Release . It is also available through some package managers: go-size-analyzer GitHub Release Homebrew (MacOS/Linux): brew install go-size-analyzer Scoop (Windows): scoop install go-size-analyzer Go Build and Install: go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest The compiled version needs to download the required resource files from GitHub at runtime. These files are embedded in the precompiled versions. Homebrew (MacOS/Linux): brew install go-size-analyzer Homebrew (MacOS/Linux): Homebrew brew install go-size-analyzer brew install go-size-analyzer Scoop (Windows): scoop install go-size-analyzer Scoop (Windows): Scoop scoop install go-size-analyzer scoop install go-size-analyzer Go Build and Install: go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest The compiled version needs to download the required resource files from GitHub at runtime. These files are embedded in the precompiled versions. Go Build and Install : Go Build and Install go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest The compiled version needs to download the required resource files from GitHub at runtime. These files are embedded in the precompiled versions. Usage Run gsa --version to ensure go-size-analyzer is installed correctly. gsa --version go-size-analyzer Locate the binary you want to analyze. Here, we choose the Linux x86_64 version of CockroachDB. gsa --web cockroach-linux-amd64 gsa --web cockroach-linux-amd64 Wait for the command line to display: Use your browser to visit http://localhost:8080 , and you will see: http://localhost:8080 If this is your project, you can click on the package name on the left to see specific details. Is there a rarely used dependency taking up a lot of space? Has embed included extra files? embed A simpler way is to check the sections on the right. We can see that the .debug_* segments take up a lot of space. .debug_* Using go tool link --help to view the specific parameters of Go's linker, we find: go tool link --help -s disable symbol table -strictdups int sanity check duplicate symbol contents during object file reading (1=warn 2=err). -tmpdir directory use directory for temporary files -v print link trace -w disable DWARF generation -s disable symbol table -strictdups int sanity check duplicate symbol contents during object file reading (1=warn 2=err). -tmpdir directory use directory for temporary files -v print link trace -w disable DWARF generation This means using the -s -w parameters can remove the .symtab and .debug_* segments, saving about 40M of space in this binary. -s -w .symtab .debug_* 40M To pass parameters to the linker during compilation, you can use the -ldflags parameter. The complete command would be go build -ldflags="-s -w" . -ldflags go build -ldflags="-s -w" Summary In this article, we introduced how to use the go-size-analyzer tool to analyze the size of Go application binaries. This tool allows you to visualize the space occupied by different parts of your program and identify areas for optimization. We found that in many cases, the .debug_* segments take up a considerable amount of space, and using the -s -w parameters of the Go linker can significantly reduce the binary size. go-size-analyzer .debug_* -s -w If you find this tool helpful, consider visiting my GitHub repository at https://github.com/Zxilly/go-size-analyzer and giving it a star. Your support is very important to me, as it not only motivates me to continue improving this tool but also helps more people discover this useful resource. https://github.com/Zxilly/go-size-analyzer