-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Change branching in iter.skip()
#80715
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
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
But does it improve the motivating example, i.e. the |
Hm I'm not particularly sure about that specific example, but I'll try to provide more cases in the godbolt to compare against. |
I was not seeing much difference in the provided godbolt, so I made up my own, simpler, test cases https://godbolt.org/z/9P8Tej and I still am having hard time seeing whether one is better than the other, both look very similar to me. So I think you may have better success if you find an example where the improvements are very obvious, write a benchmark or describe more precisely why the codegen in with proposed code is better. r? @nagisa |
I'm compiling the benchmarks which use skip in core, but it takes like a good 2 hrs for it to compile on my machine so it may be a bit before I have results |
New impl benchmarks:
New impl w/o
Old impl benchmark:
|
To bench changes in libcore you can do a stage 0 build. |
These wins don't seem as dramatic as the improvements in #80416 |
Ah I was compiling stage 1 but I'll do stage 0 in the future. I think for that specifically, an eager iteration w/ nth is fine, so it removes the branching and doesn't need to does as much compiler magic. For the |
Ah, maybe I misunderstood, I thought the goal was to fix the reported issue rather than this being a tangential optimization.
Possibly a custom |
@bors r+ |
📌 Commit e5094a2 has been approved by |
☀️ Test successful - checks-actions |
Optimize branching in
Skip
, which was brought up in #80416.This assumes that if
next
is called, it's likely that there will be more calls tonext
, and the branch for skip will only be hit once thus it's unlikely to take that path. Even w/o theunlikely
intrinsic, it compiles more efficiently, I believe because the path wherenext
is called is always taken.It should be noted there are very few places in the compiler where
Skip
is used, so probably won't have a noticeable perf impact.New impl
Old impl
Some additional asm examples although they really don't have a ton of difference between them.