rust-lang / rust-lang/rust

Iterator performance regression 1.81 -> 1.82

Open
#137,727 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug P-medium regression-untriaged T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

I tried this code:

use std::time::Instant;

fn main() {
    let start = Instant::now();

    (0..=1000)
    .flat_map(|a| {
        (0..=1000).flat_map(move |b| {
            (0..=1000)
                .filter(move |&c| a * a + b * b == c * c && a + b + c == 1000)
                .map(move |c| (a, b, c))
        })
    })
    .for_each(|(a, b, c)| {
        println!("a: {} b: {} c: {}", a, b, c);
    });

    let duration = start.elapsed();
    println!("{} seconds", duration.as_secs_f64());
}

I expected to see this happen: code behaves the same across compiler versions

Instead, this happened: code runs 80% slower when compiled with Rust 1.82+

Version it worked on

It most recently worked on: Rust 1.81

Version with regression

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-pc-windows-msvc
release: 1.82.0
LLVM version: 19.1.1
More details in this post

https://internals.rust-lang.org/t/iterator-performance-regression-1-81-1-82/22473

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 reproducing the supplied iterator example with Rust 1.81 and 1.82 on the reported Windows target, then read the linked Internals post for investigation context. Compare compiler behavior across those versions and narrow down the source of the regression; done means the example no longer suffers the reported slowdown in the affected release.

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
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.