Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array::IntoIter does not get optimized as well as vec::IntoIter #87949

Open
vandenheuvel opened this issue Aug 12, 2021 · 1 comment
Open

array::IntoIter does not get optimized as well as vec::IntoIter #87949

vandenheuvel opened this issue Aug 12, 2021 · 1 comment
Labels
A-array Area: `[T; N]`

Comments

@vandenheuvel
Copy link
Contributor

I found a situation where creation, conversion into an iterator and consuming the iterator gets optimized for a Vec, but not for an array.

Compiler explorer

The snipped on the left works well; the abstracted function compiles down to the same code as the goal function. The snipped on the right has the Vec usage replaced by an array. The assembler for the abstracted function is now more complicated than goal function.

Note that if one removes the Enum::Single variant, it does work.

I attempted to make the above example minimal. A more elaborate example is here.

Should this be mentioned in #84513?

@the8472
Copy link
Member

the8472 commented Aug 12, 2021

The assembly doesn't really seem much worse. No extra loops, jumps or function calls. No memory accesses at all, it's all in registers. The code also seems pretty artificial, why have an empty variant that wraps an iter::Empty if that variant could just return None directly.

Imo a better example that demonstrates significant performance issues is needed.

@workingjubilee workingjubilee added the A-array Area: `[T; N]` label Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-array Area: `[T; N]`
Projects
None yet
Development

No branches or pull requests

3 participants