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 --force --git https://github.com/RazrFalcon/cargo-bloat.git

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.0% 93.3% 4.1MiB [8671 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.2% 0.5% 22.9KiB cargo::ops::cargorustc::jobqueue::JobQueue::drainthe_queue 40.8% 100.0% 4.3MiB .text section size, the file size is 10.7MiB ```

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.8% 1.2MiB cargo 8.4% 20.6% 918.1KiB std 7.5% 18.3% 815.0KiB [Unknown] 2.2% 5.4% 240.5KiB toml 1.9% 4.7% 210.4KiB regex 1.9% 4.7% 207.7KiB goblin 1.1% 2.8% 124.7KiB serdeignored 1.0% 2.5% 110.8KiB regexsyntax 0.9% 2.1% 95.2KiB serde_json 0.8% 1.9% 84.5KiB docopt 40.8% 100.0% 4.3MiB .text section size, the file size is 10.7MiB ```

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. --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.