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

Document iter().copied() vs iter() for small data types #83

Open
Dan-wanna-M opened this issue Jun 11, 2024 · 1 comment
Open

Document iter().copied() vs iter() for small data types #83

Dan-wanna-M opened this issue Jun 11, 2024 · 1 comment

Comments

@Dan-wanna-M
Copy link

As the issues rust-lang/rust#106539 and rust-lang/rust#113789 indicate, iter().copied() is more efficient than iter() for small data types because the former one results in less indirections and hence opens up the room for more optimizations. How small is small needs more investigations, but anything <= usize should definitely be small(in fact, the original reply in the issue suggests 8*usize is probably still small enough).

@Dan-wanna-M Dan-wanna-M changed the title Document performance difference between iter().copied() and iter() for small data types Document iter().copied() vs iter() for small data types Jun 11, 2024
@Shnatsel
Copy link
Contributor

Indeed, there is a comment form a compiler developer that this is extremely difficult for LLVM to optimize, and that putting .copied() early should be encouraged: rust-lang/rust#106539 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants