Skip to content

Figure out how to make symbolisation code smaller #139209

Open
@joboet

Description

@joboet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-backtraceArea: BacktracesC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-heavyIssue: Problems and improvements with respect to binary size of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions