top | item 44306152

(no title)

drabbiticus | 8 months ago

First off, the display looks great!

Second off, I didn't realize how deep the dep tree would be for this type of program -- 141 total! So much of it is the url crate, itself a dep of the git crate, but there's a bunch of others too. I'm just getting into learning Rust -- is this typical of Rust projects or perhaps typical of TUI projects in general?

(EDIT to strikeout) ~~The binary is also 53M as a result whereas /usr/sbin/tree is 80K on my machine -- not really a problem on today's storage, but very roughly 500-1000x different in size isn't nothing.~~

Maybe it's linking-related? I don't know how to check really.

(EDIT: many have pointed out that you can run `cargo build --release` with other options to get a much smaller binary. Thanks for teaching me!)

discuss

order

JoshTriplett|8 months ago

> The binary is also 53M

That's a debug binary, and the vast majority of that is debug symbols. A release build of this project is 4.3M, an order of magnitude smaller.

Also, compiling out the default features of the git2 crate eliminates several dependencies and reduces it further to 3.6M.

https://github.com/bgreenwell/lstr/pull/5

https://github.com/rust-lang/git2-rs/pull/1168

Stripping the binary further improves it to 2.9M, and some further optimizations get it to 2.2M without any compromise to performance. (You can get it smaller by optimizing for size, but I wouldn't recommend that unless you really do value size more than performance.)

esafak|8 months ago

No offense, but 4.3MB is huge for what it does. Most shells take less space than that! Where's all the bloat coming from?

pveierland|8 months ago

Building in release:

  cargo build --release
  du -sh ./target/release/lstr -> 4.4M
Building with other release options brings it down to 2.3M:

  [profile.release]
  codegen-units = 1
  opt-level = "s"
  lto = true
  panic = "abort"
  strip = "symbols"

cyann|8 months ago

I did some benchmarks on one of our CLI and found that `opt-level = "z"` reduced the size from 2.68M to 2.28M, and shaved 10% on the build time, worth a try.

I'll try with `panic = "abort"` for our next release, thanks for the reminder.

fabrice_d|8 months ago

You are probably looking at a debug build. On Linux, a release build (cargo build -r) is ~4.3M, and down to ~3.5M once stripped. This could be reduced further with some tricks applied to the release build profile.

getcrunk|8 months ago

Great catch! Comments mentioned getting it down to ~2MB but that’s still humongous.

If you just think about how roughly (napkin math) 2MB can be 100k loc, that’s nuts

arlort|8 months ago

Is It though? You won't get it on an embedded device (maybe) but you could install a thousand of these tools and barely even notice the space being taken up on most machines

vlovich123|8 months ago

When you include the code for all the dependency features this uses, you probably do end up close to 100k LoC net, no?

ethan_smith|8 months ago

Try `cargo build --release --no-default-features` to get a much smaller binary (~5-10MB) - Rust statically links dependencies but supports conditional compilation for optional features.

aystatic|8 months ago

Glancing at the Cargo.toml, the package doesn't define any features anyways. `cargo b --no-default-features` only applies to the packages you're building, not their dependencies -- that would lead to very unpredictable behavior