Skip to content

Iterator performance regression 1.81 -> 1.82 #137727

Open

Description

@Sunshine40

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

Activity

  1. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 27, 2025
  2. Sunshine40 commented on Feb 27, 2025

    @Sunshine40
    ContributorAuthor

    I wonder if this is somehow related to #132636?

  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Feb 27, 2025
  4. steffahn commented on Feb 27, 2025

    @steffahn
    Member
    searched toolchains nightly-2024-07-20 through nightly-2024-08-30
    
    
    ********************************************************************************
    Regression in nightly-2024-08-01
    ********************************************************************************
    
    fetching https://static.rust-lang.org/dist/2024-07-31/channel-rust-nightly-git-commit-hash.txt
    nightly manifest 2024-07-31: 40 B / 40 B [====================================================================] 100.00 % 165.01 KB/s converted 2024-07-31 to f8060d282d42770fadd73905e3eefb85660d3278
    fetching https://static.rust-lang.org/dist/2024-08-01/channel-rust-nightly-git-commit-hash.txt
    nightly manifest 2024-08-01: 40 B / 40 B [====================================================================] 100.00 % 249.29 KB/s converted 2024-08-01 to 28a58f2fa7f0c46b8fab8237c02471a915924fe5
    looking for regression commit between 2024-07-31 and 2024-08-01
    fetching (via remote github) commits from max(f8060d282d42770fadd73905e3eefb85660d3278, 2024-07-29) to 28a58f2fa7f0c46b8fab8237c02471a915924fe5
    ending github query because we found starting sha: f8060d282d42770fadd73905e3eefb85660d3278
    get_commits_between returning commits, len: 7
      commit[0] 2024-07-30: Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68
      commit[1] 2024-07-30: Auto merge of #128413 - matthiaskrgr:rollup-nrfcvdq, r=matthiaskrgr
      commit[2] 2024-07-31: Auto merge of #128075 - Oneirical:try-your-damnetest, r=jieyouxu
      commit[3] 2024-07-31: Auto merge of #128420 - weihanglo:update-cargo, r=weihanglo
      commit[4] 2024-07-31: Auto merge of #127513 - nikic:llvm-19, r=cuviper
      commit[5] 2024-07-31: Auto merge of #128435 - matthiaskrgr:rollup-l76vu3i, r=matthiaskrgr
      commit[6] 2024-07-31: Auto merge of #126991 - cjgillot:gvn-prof, r=oli-obk
    ERROR: no CI builds available between f8060d282d42770fadd73905e3eefb85660d3278 and 28a58f2fa7f0c46b8fab8237c02471a915924fe5 within last 167 days
    

    so this might be

    @rustbot label -E-needs-bisection

  5. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Feb 27, 2025
  6. nikic commented on Feb 27, 2025

    @nikic
    Contributor

    This sounds like llvm/llvm-project#81689 to me.

  7. apiraino commented on Feb 28, 2025

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-medium

  8. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Feb 28, 2025
  9. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions