cargo-bloat

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

Inspired by google/bloaty.

Note: supports ELF (Linux, BSD) and Mach-O (macOS) platforms only.

Install

bash cargo install cargo-bloat

Usage

Get a list of the biggest functions in the release build:

``` % cargo bloat --release -n 10 Compiling ... Analyzing target/release/cargo-bloat

File .text Size Crate Name 20.2% 86.6% 1.2MiB [3651 Others] 0.8% 3.2% 47.4KiB regexsyntax >::parsewithcomments 0.4% 1.8% 25.7KiB clap clap::app::parser::Parser::getmatcheswith 0.3% 1.5% 21.6KiB cargobloat cargobloat::processcrate 0.3% 1.1% 16.5KiB goblin command::CommandVariant as scroll::ctx::Tr... 0.3% 1.1% 16.0KiB clap clap::app::help::Help::writearg 0.2% 1.0% 15.3KiB clap clap::app::validator::Validator::validatematchedargs 0.2% 1.0% 14.5KiB cargobloat cargobloat::main 0.2% 0.9% 13.7KiB regex regex::exec::ExecBuilder::build 0.2% 0.9% 12.6KiB clap clap::app::help::Help::writehelp 0.2% 0.8% 12.2KiB clap clap::app::usage::getrequiredusagefrom 23.3% 100.0% 1.4MiB .text section size, the file size is 6.1MiB ```

Get a list of the biggest dependencies in the release build: ``` % cargo bloat --release --crates -n 10 Compiling ... Analyzing target/release/cargo-bloat

File .text Size Name 7.0% 29.9% 437.5KiB std 4.8% 20.5% 299.7KiB clap 3.3% 14.1% 206.7KiB regexsyntax 2.3% 9.8% 143.2KiB regex 2.2% 9.4% 137.5KiB goblin 1.6% 6.8% 99.4KiB [Unknown] 0.7% 3.1% 45.4KiB cargobloat 0.5% 2.3% 33.2KiB serdejson 0.2% 1.0% 14.8KiB object 0.2% 0.7% 10.2KiB rustcdemangle 23.3% 100.0% 1.4MiB .text section size, the file size is 6.1MiB

Note: numbers above are a result of guesswork. They are not 100% correct and never will be. ```

Get a list of the biggest functions in the release build filtered by the regexp: ``` % cargo bloat --release --filter '^__' -n 10 Compiling ... Analyzing target/release/cargo-bloat

File .text Size Crate Name 0.0% 0.0% 82B [10 Others] 0.0% 0.1% 976B std _udivmodti4 0.0% 0.0% 153B std _ruststartpanic 0.0% 0.0% 128B std _rustmaybecatchpanic 0.0% 0.0% 101B [Unknown] _libccsuinit 0.0% 0.0% 67B [Unknown] _pthreadatfork 0.0% 0.0% 45B std _rustprobestack 0.0% 0.0% 45B std _rdealloczeroed 0.0% 0.0% 45B std _rdedealloc 0.0% 0.0% 45B std _rdealloc 0.0% 0.0% 40B std _rderealloc 0.0% 0.1% 1.7KiB filtered data size, the file size is 6.1MiB ```

Flags specific for the cargo-bloat: --crates Per crate bloatedness --time Per crate build time. Will run `cargo clean` first --filter <CRATE|REGEXP> Filter functions by crate --split-std Split the 'std' crate to original crates like core, alloc, etc. --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

License

cargo-bloat is licensed under the MIT.