Skip to content
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

Please provide slimmed down version of b3sum #363

Open
Hermholtz opened this issue Nov 17, 2023 · 4 comments
Open

Please provide slimmed down version of b3sum #363

Hermholtz opened this issue Nov 17, 2023 · 4 comments

Comments

@Hermholtz
Copy link

Hello. Thanks for implementing b3sum, much needed for many purposes. I like it, it's working and all, written in trendy Rust etc., but the binary size is 1,104,376 bytes (Ubuntu 23.10), which is among the largest binaries in my /usr/bin. The bash is 1.4 MiB, and it's a complete shell with a programming language.

For embedded machines, such as Raspberry Pi, or slimmed-down containers or many other applications we'd need a single-threaded C version of b3sum officially distributed and supported.

For your reference: b2sum is only 51744 bytes, sha*sum and md*sum are also 40-50 KiB in size.

Please provide that.

Thank you.

@oconnor663
Copy link
Member

I can get it down to ~800 KB using these steps: https://github.com/johnthagen/min-sized-rust

It's possible we could save some more space by making features like Rayon and Mmap optional (though those are crucial for performance). It might also be that Clap takes up more binary space that we would prefer, though it's a bit more work to test that.

The best space-saving strategy is probably to come up with a patch for busybox to provide a b3sum command there?

@Hermholtz
Copy link
Author

Hermholtz commented Nov 18, 2023

The "example.c" which can calculate the sum compiles to an executable with length 84104. I think with additional ~10K it could parse command line and that's what's needed. Also, SSE versions could be removed, only AVX could be preserved. They wouldn't apply to ARM and many embedded targets anyway. Thanks.

@ultrabear
Copy link

If clap size is a concern, argh might be a good replacement, though it lacks functionality
tried upx? that normally shrinks stuff, though it has broken on some of my rust code before

I dont think making a C implementation alongside the existing rust implementation is worth anyones time, you can totally write small rust code if you put the time in to use libc directly and handwrite more things (even when that can lead to more bugs), but that doesn't require C

@nirs
Copy link

nirs commented Feb 26, 2024

Since we already have a C implementation which seems to be fast as single threaded Rust one, I think the best way to make it compact and available everywhere is to package the C version as a library (like it was done in Fedora), and integrate it in coreutils:
https://github.com/coreutils/coreutils/blob/master/src/digest.c

This version will slower and provides less features, but it will be on every machine and likely to be integrated in busybox.

When coreutils is rewritten in rust it can use the rust crate :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants