4 ms·
> 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
by JoshTriplett 1y 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/bgreenwell/lstr/pull/5
https://github.com/rust-lang/git2-rs/pull/1168 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 1y agoNo offense, but 4.3MB is huge for what it does. Most shells take less space than that! Where's all the bloat coming from?
- have-a-break 1y agoI feel like that's just the result of having a native package manager making natural bloat and a compiler which hasn't had decades of work.
- o11c 1y agoFor reference, some statically-linked shells on my system: 2288K /bin/bash-static (per manual, "too big and too slow") 1936K /bin/busybox-static (including tools not just the shell) 192K /usr/lib/klibc/bin/mksh 2456K zsh-static For comparison, some dynamically-linked binaries (some old) 804K ./bin/bash-3.2 888K ./bin/bash-4.0 908K ./bin/bash-4.1 956K ./bin/bash-4.2 1016K ./bin/bash-4.3 1092K ./bin/bash-4.4 1176K ./bin/bash-5.0 1208K ./bin/bash-5.1 1236K /bin/bash (5.2) 124K /bin/dash 1448K /bin/ksh93 (fattest when excluding libc!) 292K /bin/mksh 144K /bin/posh 424K /bin/yash 848K /bin/zsh (The reason I don't have static binaries handy is because they no longer run on modern systems. As long as you aren't using shitty libraries, dynamic binaries are more portable and reliable, contrary to internet "wisdom".)
- JoshTriplett 1y agoAmong the features it has: an interactive terminal GUI, threaded parallel directory walking, and git repository support. In around a thousand lines of code, total, including tests, half of which is the GUI.
- oguz-ismail 1y ago*TUI. Not GUI
- koito17 1y ago> Most shells take less space than that! Most shells dynamically link to a runtime your OS provides "for free". The 4.3 MiB binary in question is bundling the Rust runtime and its dependencies. For reference, a statically-compiled C++ "Hello, World" is 2.2 MiB after stripping. % cat hello.nix { pkgs ? import <nixpkgs> { crossSystem = "aarch64-linux"; } }: pkgs.stdenv.mkDerivation { name = "hello-static"; src = pkgs.writeText "hello.cpp" '' #include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; } ''; dontUnpack = true; buildInputs = [ pkgs.glibc.static ]; buildPhase = "$CXX -std=c++17 -static -o hello $src"; installPhase = "mkdir -p $out/bin; cp hello $out/bin/"; } % nix-build hello.nix ... % wc -c result/bin/hello 2224640 result/bin/hello
- esafak 1y ago2.2MiB for "Hello, World"? I must be getting old... The executable takes 33KB in C, 75KB in nim.
- creatonez 1y ago> The executable takes 33KB in C, 75KB in nim. Did you statically link Glibc...? Or is this with a non-GNU libc? Either way, it probably is true that this 2.2MiB number would be smaller on, say, Debian 5. And much smaller on PDP Unix.
- koito17 1y agoBy switching to e.g. musl, you can go down to a single megabyte ;) But in all seriousness, my example is quite cherrypicked, since nobody will actually statically link glibc. And even if they did, one can make use of link-time optimization to remove lots of patches of unused code. Note that this is the same strategy one would employ to debloat their Rust binaries. (Use LTO, don't aggressively inline code, etc.)
- 3836293648 1y agoJust a `puts("Hello world!")` with -Os statically linked to musl is 22k