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.
bash
cargo install cargo-bloat
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
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
--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
cargo-bloat is licensed under the MIT.