rust-lang / rust-lang/rust

Figure out how to make symbolisation code smaller

Open
#139,209 10 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-backtrace C-enhancement I-heavy T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the backtrace-rs symbolisation logic and how the -C debuginfo and -C panic options select implementation strategies. Compare the proposed dynamic-dispatch reductions with the separate-crate approach. Done means there is an agreed, demonstrated strategy for reducing release-binary size without losing backtrace functionality.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.