Exponential compile time after update to LLVM 22
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
I tried this code:
fn main() {
for _ in 0..1 {
for _ in 0..1 {
SolveDirect::<SIZE>::solve_direct(&(), 0);
}
}
}
trait SolveDirect<const N: usize> {
fn solve_direct(&self, total_sum: u32);
}
macro_rules! impl_solve_direct {
($size:literal) => {
impl SolveDirect<$size> for () {
fn solve_direct(&self, total_sum: u32) {
SolveDirect::<{ $size - 1 }>::solve_direct(self, total_sum);
let changed_total = std::hint::black_box(total_sum);
SolveDirect::<{ $size - 1 }>::solve_direct(self, changed_total);
}
}
};
}
impl SolveDirect<1> for () {
fn solve_direct(&self, total_sum: u32) {
std::hint::black_box(total_sum);
}
}
const SIZE: usize = 15;
impl_solve_direct!(2);
impl_solve_direct!(3);
impl_solve_direct!(4);
impl_solve_direct!(5);
impl_solve_direct!(6);
impl_solve_direct!(7);
impl_solve_direct!(8);
impl_solve_direct!(9);
impl_solve_direct!(10);
impl_solve_direct!(11);
impl_solve_direct!(12);
impl_solve_direct!(13);
impl_solve_direct!(14);
impl_solve_direct!(15);
I expected to see this happen:
Code compiles quickly
Instead, this happened:
The code compiles really slowly and produces huge assembly.
The assembly size increases with "recursion" depth like 2^N.
The compile time increases with "recursion" depth like 4^N.
It also should introduce function calls to reduce the assembly size of the main function.
cargo asm --simplify: (same compile time for cargo build --release))
N = 13:
cargo asm --simplify
Finished `release` profile [optimized] target(s) in 2.52s
Try one of those by name or a sequence number
0 "<std::rt::lang_start<()>::{closure#0} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}" [20]
1 "main" [18]
2 "qubo_test::main" [53254]
3 "std::rt::lang_start::<()>" [28]
4 "std::rt::lang_start::<()>::{closure#0}" [19]
5 "std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>" [22]
N = 14:
cargo asm --simplify
Finished `release` profile [optimized] target(s) in 9.98s
Try one of those by name or a sequence number
0 "<std::rt::lang_start<()>::{closure#0} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}" [20]
1 "main" [18]
2 "qubo_test::main" [106502]
3 "std::rt::lang_start::<()>" [28]
4 "std::rt::lang_start::<()>::{closure#0}" [19]
5 "std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>" [22]
N = 15:
Finished `release` profile [optimized] target(s) in 40.06s
Try one of those by name or a sequence number
0 "<std::rt::lang_start<()>::{closure#0} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}" [20]
1 "main" [18]
2 "qubo_test::main" [212999]
3 "std::rt::lang_start::<()>" [28]
4 "std::rt::lang_start::<()>::{closure#0}" [19]
5 "std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>" [22]
On stable:
cargo asm --simplify:
Compiling qubo_test v0.1.0
Finished `release` profile [optimized] target(s) in 0.06s
0 "<() as qubo_test::SolveDirect<11_usize>>::solve_direct" [101]
1 "<() as qubo_test::SolveDirect<14_usize>>::solve_direct" [101]
2 "<() as qubo_test::SolveDirect<5_usize>>::solve_direct" [210]
3 "<() as qubo_test::SolveDirect<8_usize>>::solve_direct" [101]
4 "core::ops::function::FnOnce::call_once{{vtable.shim}}" [20]
5 "main" [18]
6 "qubo_test::main" [26]
7 "std::rt::lang_start" [28]
8 "std::rt::lang_start::{{closure}}" [19]
9 "std::sys::backtrace::__rust_begin_short_backtrace" [22]
Version it worked on
Used bisect-rustc to find offending commit.
It's the update to LLVM 22
********************************************************************************
Regression in 466ea4e6c39f8a43727edcc726ca86b499e14d83
********************************************************************************
Attempting to search unrolled perf builds
ERROR: couldn't find perf build comment
==================================================================================
= Please file this regression report on the rust-lang/rust GitHub repository =
= New issue: https://github.com/rust-lang/rust/issues/new =
= Known issues: https://github.com/rust-lang/rust/issues =
= Copy and paste the text below into the issue report thread. Thanks! =
==================================================================================
searched nightlies: from nightly-2025-06-01 to nightly-2026-02-16
regressed nightly: nightly-2026-01-29
searched commit range: https://github.com/rust-lang/rust/compare/e96bb7e44fbcc23c1e6009e8d0ee8ab208668fb4...de6d33c033441c5880b863f94d7a3ec8cad141bd
regressed commit: https://github.com/rust-lang/rust/commit/466ea4e6c39f8a43727edcc726ca86b499e14d83
<details>
<summary>bisected with <a href='https://github.com/rust-lang/cargo-bisect-rustc'>cargo-bisect-rustc</a> v0.6.11</summary>
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
```bash
cargo bisect-rustc --start=2025-06-01 --end=2026-2-16 --timeout 1 -- build --release
```
-->
Version with regression
rustc --version --verbose:
rustc 1.95.0-nightly (873b4beb0 2026-02-15)
binary: rustc
commit-hash: 873b4beb0cc726493b94c8ef21f68795c04fbbc1
commit-date: 2026-02-15
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0
@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin by reproducing the minimal Rust program with the reported nightly and compare it with the pre-regression version identified by cargo-bisect-rustc. Inspect commit 466ea4e6c39f8a43727edcc726ca86b499e14d83 and the LLVM 22 update, using cargo build --release and the reported assembly output. Done means the exponential compile time and assembly growth are resolved and the regression is covered by an appropriate compiler test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100