-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shrink moonfire-nvr binary #70
Comments
Benefits: * Blake3 is faster. This is most noticeable for the hashing of the sample file data. * we no longer need OpenSSL, which helps with shrinking the binary size (#70). sha1 basically forced OpenSSL usage; ring deliberately doesn't support this old algorithm, and the pure-Rust sha1 crate is painfully slow. OpenSSL might still be a better choice than ring/rustls for TLS but it's nice to have the option. For the video sample entries, I decided we don't need to hash at all. I think the id number is sufficiently stable, and it's okay---perhaps even desirable---if an existing init segment changes for fixes like e5b83c2.
The split debug symbols (aka "fission") would currently break backtraces, unfortunately: |
A couple reasons for this: * the docopt crate is "unlikely to see significant future evolution", and the wider docopt project is "mostly unmaintained at this point". clap/structopt is more full-featured, has more natural subcommand support, etc. * it may allow me to shrink the binary (#70). This change alone seems to be a slight regression, but it's a step toward getting rid of regex, which is pretty large. And I feel less ridiculous now that I don't have two parsing crates anyway; prettydiff was pulling in structopt. There are some behavior changes here: * misc --help output changes and such as you'd expect from switching argument-parsing libraries * I properly used PathBuf and OsString for stuff that theoretically could be non-UTF-8. I haven't tested that it actually made any difference. I'm also still storing the sample file dirname as "text" in the database to avoid causing a diff when not doing a schema change.
This reduces the binary size noticeably on my macOS machine (#70): unstripped stripped 1 before switching to clap 11.1 MiB 6.7 MiB 2 after switching to clap 11.4 MiB 6.9 MiB 3 without regex 10.1 MiB 5.9 MiB
There are many (10+) duplicate packages with different versions. This is likely increasing the size to some degree. These can be reduced by using dependencies with matching dependency versions. Here's a quick list:
For the depedency graph, use |
Definitely not ideal, although I suspect none of the ones in that list are a major contribution to the binary size given the |
As of 0.7.0, no duplicate packages!
Biggest likely-fixable contributors that are still around: debug info (file size minus
|
This trims ~700KiB off moonfire-nvr's text section, much of it by eliminating h2. See #70.
This reduces the binary size from 154 MiB to 70 MiB (#70 progress). Tools like `cargo flamegraph` still work fine. As suggested by "EarthFeet" on reddit: https://www.reddit.com/r/rust/comments/rw0jad/cargos_strip_profile_option_has_been_stabilized/hra193k/
With 0406e09, the binary shrunk from 154 MiB to 70 MiB. I'm still hoping to reduce it further with split debug info. From this comment and this PR it looks like work is actively being done on that. |
Improves #70: this reduces binary size from 12.3 MiB to 11.9 MiB (3%) on macOS/arm64. The user experience is almost the same. (The help output's `Usage:` lines lack the e.g. `moonfire-nvr run` prefix of argv[0] and subcommand, which isn't ideal, but I guess it's pretty minor in the grand scheme of things.)
There's some significant bloat in the binary right now:
protobuf
. It's surprisingly large; maybe there's some low-hanging fruit or we could switch toprost
.regex
. This was a convenient way of doing my parsing, but it's not strictly necessary, andcargo bloat
says it's pretty large.cursive
. It's a lovely library, but long-term I want a web config UI (web configuration UI #35) instead.openssl
andring
.libpasta
usesring
iirc. I could just stop usingopenssl
, although that might not be a good choice when I actually have built-in https (good Internet-facing webserver #27) [Currently I've eliminated openssl in thenew-schema
branch. It's not yet merged tomaster
.]clap
anddocopt
. I usedocopt
.prettydiff
is pulling inclap
, which at first glance seems silly. I might convert to clap anyway though so maybe there's no point in messing with prettydiff.parking_lot
. (tokio currently uses 0.7; I use 0.9 in moonfire-{nvr,db,base} and in mylog.) tokio is likely to update soon-ish, so I can probably just wait for this to be fixed.These aren't causing material problems right now; the big binaries are just a bit embarrassing. So no particular size we need to get under or anything.
The text was updated successfully, but these errors were encountered: