Repository navigation
Performance regression of array::IntoIter vs slice::Iter #115339
Description
Activity
- addedC-bugCategory: This is a bug.Category: This is a bug.regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
on Aug 29, 2023 - addedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.and removedregression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
on Aug 29, 2023 WG-prioritization assigning priority (Zulip discussion).
cc @nikic since this regressed in the LLVM 15 update
@rustbot label -I-prioritize +P-medium +T-compiler
- addedP-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.and removedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on Aug 29, 2023 - addedA-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
on Aug 29, 2023 I've seen llvm doing these strange 1-byte-at-a-time "vectorizations" in other places too. This might be a more general problem.
In this case we can probably paper over it by implementing TrustedRandomAccess for the array iter.
- removedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Aug 29, 2023 Unfortunately, the array iterator is fundamentally worse right now, because indexing into it -- a fundamental part of being a by-value array iterator -- keeps it from SRoAing and thus doesn't optimize well.
This is why when I was making
array::mapbetter I ended up making https://github.com/rust-lang/rust/pull/107634/files#diff-d391813c2568a5afd0555e6224d5168993b6ada448c4f1397799cb98b5b8a18b to not have to usearray::IntoIter.Sadly, for the foreseeable future you're better off using the "weaker" slice iterator when you can.
Reacted by DaniPopesMy guess is that the SROA is missing something in the opaque pointer mode.
@rustbot claim
It's not about vectorization. This optimization can be restored by using
-Cllvm-args=-opaque-pointers=0. But highly unrecommended. https://godbolt.org/z/GqdPGarsnUpstream issue: llvm/llvm-project#65763.
The upstream issue is closed.
@rustbot claimReacted by Michael VelbaumReacted by scottmcm- addedllvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
on Sep 20, 2023 - added a commit that references this issue
on Oct 6, 2023 - addedC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing such
on Oct 8, 2023 - added a commit that references this issue
on Oct 15, 2023
Code
I tried this code:
I expected to see this happen: same codegen or similar in performance
Instead, this happened: array has way worse codegen
godbolt
Assembly
Version it worked on
It most recently worked on: 1.64
Version with regression
1.65 till now.
Regressed in nightly-2022-08-13, maybe LLVM 15 #99464?:
rustc --version --verbose:Backtrace
Backtrace
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged