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 Go 1.11 modules
Output as JSON for tracking and/or monitoring as part of CI

Quick Start

With Go Modules - Go 1.11 or higher

$ go get github.com/jondot/goweight
$ cd current-project
$ goweight

Without Go Modules - Before Go 1.11

$ git clone https://github.com/jondot/goweight
$ cd goweight
$ go install

$ cd current-project
$ goweight

As an example, here's what goweight has to say about itself:

$ ./goweight
  3.0 MB runtime
  1.6 MB net
  1.4 MB reflect
  1.3 MB gopkg.in/alecthomas/kingpin.v2
  870 kB math/big
  668 kB github.com/alecthomas/template
  628 kB syscall
  626 kB text/template
  550 kB go/ast
  546 kB encoding/json
  509 kB text/template/parse
  495 kB github.com/alecthomas/template/parse
  424 kB time
  402 kB regexp/syntax
  395 kB golang_org/x/net/dns/dnsmessage
  388 kB fmt

Thanks:

To all Contributors - you make this happen, thanks!

Copyright

Copyright (c) 2018 @jondot. See LICENSE for further details.

Owner
Comments
  • Making it work on already compiled binaries

    Making it work on already compiled binaries

    I'm trying to use this for fairly complex projects like Kubernetes server components that are already pre-built.

    Is it possible to make this work on compiled binaries like the blog post at https://science.raphael.poss.name/go-executable-size-visualization-with-d3.html explains?

  • How to handle projects created with gb package manager

    How to handle projects created with gb package manager

    I have a project created with gb pacakge manager and how can i execute the goweight command ?I see the following issue when i execute

    # goweight
    2019/04/04 18:12:17 exit status 1
    
  • Doesn't work if there's more than one main() function

    Doesn't work if there's more than one main() function

    I know this shouldn't happen, but I have a helper program that builds my project for different GOOS/GOARCH concurrently that resides within the project, along with the main.go.

    If I run goweight, it exits with:

    2019/04/03 10:58:28 exit status 2
    

    Maybe there should be some way to define which .go files should be used to compile, or to exclude?

  • go get fails

    go get fails

    > go get github.com/jondot/goweight
    package goweight/pkg: unrecognized import path "goweight/pkg" (import path does not begin with hostname)
    
  • exit status 2

    exit status 2

    I'm trying to use the tool, but it does not work and does not report why:

    $ go get github.com/jondot/goweight
    $ goweight
    2021/08/31 11:00:22 exit status 2
    $ goweight --version
    dev (none)
    
  • Support for build tags

    Support for build tags

    My package imports a quite heavyweight library when certain build tag is specified. It would be nice to able to see how it contributes to the binary size.

    Something like goweight -tags 'use_heavy_lib'

  • Always getting `operation not permitted` all projects

    Always getting `operation not permitted` all projects

    I am getting an error while trying this out on an example project. Any ideas?

    1. $ git clone https://github.com/jondot/goweight
    2. Jump to your project
    3. $ goweight
    4. See the error: operation not permitted

    macOS - Go v1.15.5

  • remove redundant dependencies

    remove redundant dependencies

    I use this tool all the time. As well as a large number of gophers around the world. Therefore, I thought that reducing the number of dependencies would be a very useful step for the development of this project. That's why:

    1. Faster installation, by reducing the number of network requests to get dependencies. On the cheapest VPS, the original goweight was installed in 31.402s, mine in 8.363s. This is almost 4x acceleration
    2. Barely noticeable acceleration of startup by reducing the size of the executable file. It's almost imperceptible in a single run, but small wins add up to big wins when the tool is run hundreds of times every day by thousands of people around the world.
    3. Reproducibility of builds and user safety. Over time, projects are abandoned, APIs change, github may be unavailable, and sometimes developer accounts are hacked to embed malicious functionality into library code. When we are not dependent on third-party solutions, we can be more confident that the project can be compiled without fear of "infection" and / or problems with the inaccessibility of something.

    Binary size reduction on amd64 linux: 5848 B -> 3028 B

    P.S. I would like to further develop and support goweight, which has not seen a release since May 2019. Assigning me as a maintainer will greatly help me improve the quality of the project and add more features to it. thanks

  • Don't force recompilation

    Don't force recompilation

    This project is most useful it seems for projects which produce large binaries and which have many dependencies. Such projects can take a long time to build. Thus, I suggest removing the -a flag from the build command. I do not know if it provides any value, because it's been there since the first commit. https://github.com/jondot/goweight/blob/624b44a7a73a54fe24a2061cca7030ff8855d488/pkg/goweight.go#L57

    $ go help build
    -a
        force rebuilding of packages that are already up-to-date.
    
  • size does not seem to be accurate

    size does not seem to be accurate

    First of all, thanks for sharing this tool, I found it very useful.

    I've been analysing my binaries with this and I see that the sum of all sizes is much more than the final binary size. Is there any explanation to this? is there any way to know how much smaller a certain binary will be if I remove a dependency?

    The tool is still very useful to focus on the biggest contributing dependencies, but sometimes I see a dependency of 6Mb for example, and after removing it completely I see the final binary only decreased 2Mb for example. I'd like to understand where the delta comes from.

  • Quick start instructions are swapped

    Quick start instructions are swapped

    The quick start instructions were correct, but this commit inverted them:

    https://github.com/jondot/goweight/commit/746c1a5c7d649ec5d3faed6f9fe4d687b5c22a91

    I think that commit should be reverted.

Related tags
Packiffer is a lightweight cross-platform networking toolkit that let you sniff/analyze/inject/filter packets.
Packiffer is a lightweight cross-platform networking toolkit that let you sniff/analyze/inject/filter packets.

Packiffer is a lightweight cross-platform networking toolkit that let you sniff/analyze/inject/filter packets.

Dec 19, 2022
Simple HTTP/HTTPS proxy - designed to be distributed as a self-contained binary that can be dropped in anywhere and run.

Simple Proxy This is a simple HTTP/HTTPS proxy - designed to be distributed as a self-contained binary that can be dropped in anywhere and run. Code b

Jan 7, 2023
Instant, disposable, single-binary web based live chat server. Go + VueJS.
Instant, disposable, single-binary web based live chat server. Go + VueJS.

Niltalk Niltalk is a web based disposable chat server. It allows users to create password protected disposable, ephemeral chatrooms and invite peers t

Jan 4, 2023
Golang binary for data exfiltration with ICMP protocol
Golang binary for data exfiltration with ICMP protocol

QueenSono ICMP Data Exfiltration A Golang Package for Data Exfiltration with ICMP protocol. QueenSono tool only relies on the fact that ICMP protocol

Jan 3, 2023
provides alternative to simlinking with a configurable proxy binary

Shim Shim is a standalone binary used for shimming executables instead of relying on symlinks. Shim is based on the chocolatey shim https://docs.choco

Oct 21, 2021
Implementing SPEEDEX price computation engine in Golang as a standalone binary that exchanges can call

speedex-standalone Implementing SPEEDEX price computation engine in Golang as a standalone binary that exchanges can call. Notes from Geoff About Tato

Dec 1, 2021
This app brings the Matterbridge binary to your server to connect Nextcloud Talk with other chat services

This app brings the Matterbridge binary to your server to connect Nextcloud Talk with other chat services

Sep 12, 2022
Easy to use arbitrarily-ordered encoding/binary.ByteOrder

byteorder byteorder is a Go module for working with arbitrarily-ordered byte slices. It is useful e.g. when dealing with Modbus wire formats. Installa

Dec 5, 2021
Server-tool - A simple tool to run and create Minecraft servers

Server Tool A simple tool to run and maintain different Minecraft servers. This

Dec 15, 2022
This is a tool that allows you to check minecraft names availability, this tool can do around 3000~ names a minute or more!

Checker This is a tool that allows you to check minecraft names availability, this tool can do around 3000~ names a minute or more! Tutorial To instal

Feb 13, 2022
Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files
Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files

Traefik Config Validator Note This is currently pre-release software. traefik-config-validator is a CLI tool to (syntactically) validate your Traefik

Dec 16, 2021
A tool that makes http requests and outputs the url and the content (optionally to file)

BKK Basic Crawler A tool that makes http requests and outputs the url and the content (optionally to file) How to run.. the tests go test the compiler

Nov 8, 2021
A quick and dirty but useful tool to download each text/html page from the wayback machine for a specific domain and search for keywords within the saved content

wayback-keyword-search A quick and dirty but useful tool to download each text/html page from the wayback machine for a specific domain and search for

Dec 2, 2022
PinGo is a standalone and feature-rich tool for common IP-based reachability checking tasks. Ping or Trace and Observe in real-time the statistics.

pingo As a network champion from designing and implementing to troubleshooting large scale networks - I know that is usually not easy for administrato

Sep 26, 2022
Golang tool to parse netblocks and domain names from SPF and get information about ASN
Golang tool to parse netblocks and domain names from SPF and get information about ASN

gospf Example Install go get github.com/incogbyte/gospf # get from releases ht

Nov 14, 2022
A C/S Tool to Download Torrent Remotely and Retrieve Files Back Over HTTP at Full Speed without ISP Torrent Limitation.

remote-torrent Download Torrent Remotely and Retrieve Files Over HTTP at Full Speed without ISP Torrent Limitation. This repository is an extension to

Sep 30, 2022