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 Finished release [optimized] target(s) in 0.2 secs Analyzing target/release/cargo-bloat
File .text Size Crate Name
36.7% 95.5% 5.3MiB [14430 Others]
0.3% 0.9% 48.8KiB regexsyntax
Get a list of the biggest dependencies in the release build: ``` % cargo bloat --release --crates -n 10 Finished release [optimized] target(s) in 0.2 secs Analyzing target/release/cargo-bloat
File .text Size Name 11.6% 30.2% 1.7MiB cargo 8.1% 21.2% 1.2MiB std 2.6% 6.7% 385.2KiB toml 2.3% 6.0% 342.4KiB [Unknown] 2.2% 5.7% 322.7KiB libgit2sys 2.0% 5.3% 303.8KiB clap 1.4% 3.6% 207.2KiB regexsyntax 1.1% 2.8% 160.2KiB regex 1.0% 2.6% 148.4KiB goblin 0.9% 2.3% 131.8KiB serde_json 38.5% 100.0% 5.6MiB .text section size, the file size is 14.5MiB
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 Finished release [optimized] target(s) in 0.2 secs Analyzing target/release/cargo-bloat
File .text Size Crate Name 0.0% 0.0% 1.3KiB [25 Others] 0.0% 0.1% 4.7KiB backtracesys _rbtbacktracedwarfadd 0.0% 0.1% 3.0KiB backtracesys _rbtbacktraceqsort 0.0% 0.0% 1000B std _udivmodti4 0.0% 0.0% 565B backtracesys _rbtbacktracesyminfo 0.0% 0.0% 565B backtracesys _rbtbacktracepcinfo 0.0% 0.0% 357B backtracesys _rbtbacktraceinitialize 0.0% 0.0% 219B backtracesys _rbtbacktracegetview 0.0% 0.0% 211B backtracesys _rbtbacktracevectorgrow 0.0% 0.0% 197B backtracesys _rbtbacktracecreatestate 0.0% 0.0% 150B backtracesys _rbtbacktrace_open 0.1% 0.2% 12.2KiB filtered data size, the file size is 14.5MiB ```
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.