rust-lang / rust-lang/rust

backtraces from debug assertion rustc are very slow

Open
#158,969 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage requires-debug-assertions T-bootstrap
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

View all comments

given an ice like

fn main() {
    break rust;
}

running rustc on it and getting the backtrace takes around 0.072 seconds.

with debug assertions, it takes around 6.5 seconds which is around 90 times slower which is surprising.
I don't know since when this is happening but my gut says its probably recent.

There is a noticeable pause after

thread 'rustc' (482933) panicked at /rustc-dev/f10db292a3733b5c67c8da8c7661195ff4b05774/compiler/rustc_hir_typeck/src/lib.rs:697:10:
Box<dyn Any>
stack backtrace:

right before it prints the actual backtraces 🤔

timings:

time:   0.000; rss:  112MB ->  114MB (   +2MB)	parse_crate
time:   0.000; rss:  122MB ->  123MB (   +1MB)	crate_injection
time:   0.004; rss:  123MB ->  134MB (  +11MB)	expand_crate
time:   0.004; rss:  123MB ->  134MB (  +11MB)	macro_expand_crate
time:   0.000; rss:  134MB ->  135MB (   +1MB)	AST_validation
time:   0.000; rss:  135MB ->  135MB (   +0MB)	compute_effective_visibilities
time:   0.000; rss:  135MB ->  135MB (   +0MB)	finalize_macro_resolutions
time:   0.021; rss:  135MB ->  166MB (  +30MB)	late_resolve_crate
error[E0425]: cannot find value `rust` in this scope
 --> a.rs:2:11
  |
2 |     break rust;
  |           ^^^^ not found in this scope

time:   0.000; rss:  166MB ->  166MB (   +0MB)	resolve_report_errors
time:   0.022; rss:  135MB ->  166MB (  +31MB)	resolve_crate
time:   0.000; rss:  169MB ->  170MB (   +0MB)	looking_for_entry_point
time:   0.000; rss:  170MB ->  170MB (   +0MB)	check_externally_implementable_items
time:   0.000; rss:  170MB ->  170MB (   +0MB)	looking_for_derive_registrar
time:   0.000; rss:  170MB ->  170MB (   +0MB)	unused_lib_feature_checking
time:   0.000; rss:  169MB ->  170MB (   +0MB)	misc_checking_1
time:   0.002; rss:  170MB ->  178MB (   +8MB)	coherence_checking
error[E0268]: `break` outside of a loop or labeled block
 --> a.rs:2:5
  |
2 |     break rust;
  |     ^^^^^^^^^^ cannot `break` outside of a loop or labeled block

error: internal compiler error: It looks like you're trying to break rust; would you like some ICE?
 --> a.rs:2:5
  |
2 |     break rust;
  |     ^^^^^^^^^^
  |
  = note: the compiler expectedly panicked. this is a feature.
  = note: we would appreciate a joke overview: https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675
  = note: rustc 1.99.0-nightly (f10db292a 2026-07-07) running on x86_64-unknown-linux-gnu
  = note: compiler flags: -Z time-passes


thread 'rustc' (483179) panicked at /rustc-dev/f10db292a3733b5c67c8da8c7661195ff4b05774/compiler/rustc_hir_typeck/src/lib.rs:697:10:
Box<dyn Any>
stack backtrace:
   0:     0x7f11f7dff9c0 - std[c8053079d20a6ade]::backtrace_rs::backtrace::libunwind::trace
                               at /rustc/f10db292a3733b5c67c8da8c7661195ff4b05774/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1:     0x7f11f7dff9c0 - std[c8053079d20a6ade]::backtrace_rs::backtrace::trace_unsynchronized::<std[c8053079d20a6ade]::sys::backtrace::_print_fmt::{closure#1}>
                               at /rustc/f10db292a3733b5c67c8da8c7661195ff4b05774/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
...
...
...
 141:     0x7f11f7dfb4df - <std[c8053079d20a6ade]::sys::thread::unix::Thread>::new::thread_start
                               at /rustc/f10db292a3733b5c67c8da8c7661195ff4b05774/library/std/src/sys/thread/unix.rs:123:17
 142:     0x7f11f1c981b9 - <unknown>
 143:     0x7f11f1d1d21c - <unknown>
 144:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/im/bt/rustc-ice-2026-07-08T18_33_46-483177.txt` to your bug report

note: rustc 1.99.0-nightly (f10db292a 2026-07-07) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z time-passes

query stack during panic:
#0 [typeck_root] type-checking `main`
#1 [analysis] running analysis passes on crate `a`
end of query stack
time:   6.153; rss:  170MB -> 1946MB (+1776MB)	type_check_crate
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0268, E0425.
For more information about an error, try `rustc --explain E0268`.

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

Reproduce the ICE with the shown break rust; input and compare runs with and without debug assertions. Start at compiler/rustc_hir_typeck/src/lib.rs:697, where the panic occurs, and profile the pause before the backtrace. Done means identifying and reducing the debug-assertion slowdown while preserving the reported ICE and backtrace behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.