Description
Rust binaries are notoriously large. For instance, a simple, release-mode "Hello, world!" binary has a size of over 400 kB on my machine (ARM macOS). Much of this size (probably more than half) comes from the symbolisation that std
performs when printing backtraces, as that pulls in a DWARF parser, an ELF/Mach-O parser, four instantiations of sort
and some other things in order to support printing line numbers and file names. Annoyingly, this code is almost completely redundant when a binary is compiled with the release profile, as that profile disables the generation of the very DWARF debug info that all that code aims to use. Thus, when compiling with -C debuginfo=none
, all this code could be replaced by a simple dladdr
call without any loss of functionality.
Unfortunately, std
being pre-compiled makes fixing this is rather difficult since we can't just add a feature flag to std
and turn that on and off depending on compiler flags. My idea here would be to copy the strategy used to implement -C panic
and make -C debuginfo
select between two separate crates: one that calls back into std
to employ the backtrace-rs
logic and one that uses dladdr
or a similar platform function. I'm not sure that's feasible, however.
This issue exists to coordinate work on reducing the size of backtrace-rs
(there are some obvious some fixes like using dynamic dispatch to reduce the number of sort
instantiations) and to discuss strategies for reducing the binary size further.