cargo-bloat

Find out what takes most of the space in your executable.

Inspired by google/bloaty.

Note: Linux and macOS only.

Install

bash cargo install cargo-bloat

Usage

Get a list of biggest functions in the release build:

``` % cargo bloat --release -n 10 Finished release [optimized] target(s) in 0.2 secs

File .text Size Name 38.2% 93.3% 4.1MiB [8805 Others] 0.5% 1.3% 57.6KiB as regex::retrait::RegularExpression>::readcapturesat 0.3% 0.8% 36.3KiB regexsyntax::parser::Parser::parseexpr 0.3% 0.7% 30.1KiB ... 0.3% 0.6% 28.5KiB cargo::callmainwithoutstdin 0.2% 0.6% 27.2KiB cargo::util::toml::doreadmanifest 0.2% 0.5% 24.0KiB globset::GlobSet::new 0.2% 0.5% 23.7KiB cargo::core::resolver::encode::EncodableResolve::intoresolve 0.2% 0.5% 23.6KiB cargo::ops::cargorustc::compile_targets 0.2% 0.5% 23.0KiB f... 40.9% 100.0% 4.4MiB .text section size, the file size is 10.8MiB ```

Get a list of biggest dependencies in the release build: ``` % cargo bloat --release --crates -n 10 Finished release [optimized] target(s) in 0.2 secs

File .text Size Name 11.3% 27.6% 1.2MiB cargo 10.2% 24.9% 1.1MiB std 3.0% 7.2% 325.2KiB [Unknown] 2.7% 6.5% 293.2KiB libgit2sys 2.2% 5.3% 240.5KiB toml 2.0% 5.0% 224.7KiB goblin 1.9% 4.7% 210.4KiB regex 1.1% 2.8% 124.7KiB serdeignored 1.0% 2.5% 110.8KiB regexsyntax 0.9% 2.1% 95.2KiB serdejson 40.9% 100.0% 4.4MiB .text section size, the file size is 10.8MiB ```

Flags specific for cargo-bloat: --crates Per crate bloatedness --filter CRATE Filter functions by crate --split-std Split the 'std' crate to original crates like core, alloc, etc. --print-unknown Print methods under the '[Unknown]' tag --full-fn Print full function name with hash values -n NUM Number of lines to show, 0 to show all [default: 20] -w, --wide Do not trim long function names

Correctness

The results are not perfect since function names parsing is not perfect. Also, all non-Rust methods are skipped during crates resolving which moves jemalloc and any other C libraries to the [Unknown] section.

License

cargo-bloat is licensed under the MIT.