dtolnay/cargo-expand

Can something be done about the bloat?

Closed this issue · 2 comments

The documentation says that this crate is a wrapper around the cargo command cargo rustc --profile=check -- -Zunpretty=expanded.

I installed it in the recommended way. This downloaded over 100 dependencies and took more than 2 minutes to compile (on my old laptop). Sure, today we have plenty of clock cycles and disk space to spare, but isn't there perhaps a way to un-bloat this "simple wrapper" a bit without loosing core functionality?

Also, the resulting executable takes 9 MB on disk. This is bigger than the CPython executable. I know that rustc-created executables are big by default, but have a look here: https://www.reddit.com/r/rust/comments/cg3p5m/cargobloat_08_debloated_5x_smaller_10x_faster/

Cheers from someone who learned programming on a Sinclair ZX Spectrum with 48 K of RAM. (It already had a C compiler.)

It is not something I intend to work on, but if you want to send PRs then I can evaluate whatever tradeoffs they make.

I would expect that most of the size is from bat which bakes in syntax highlighting assets for various grammars.

Thanks for the quick reply.

One very easy measure you could take is adding the following stanza to Cargo.toml as recommended by https://github.com/johnthagen/min-sized-rust:

[profile.release]
opt-level = "z"     # Optimize for size.
lto = true          # Enable Link Time Optimization
codegen-units = 1   # Reduce number of codegen units to increase optimizations.
panic = "abort"     # Abort on panic
strip = true        # Automatically strip symbols from the binary.

For cargo-expand this reduces the executable size by 50%. I wouldn't even be surprised if this provided a net performance benefit, due to more compact code - but performance should not be relevant for cargo-expand anyway.

I would expect that most of the size is from bat which bakes in syntax highlighting assets for various grammars.

IMHO the default syntax highlighting is of questionable usefulness. Not only it breaks the initial experience for people using a light background. A user will likely already use some highlighting scheme in the editor, so using a different scheme by default is not necessarily helpful.