Uh oh!
There was an error while loading. Please reload this page.
Implement nth_back for slice::{Iter, IterMut} - #60772
Conversation
rust-highfive
commented
May 12, 2019
r? @TimNN (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Maybe add a debug_assert making sure mem::size_of::<T>() == 0?
There was a problem hiding this comment.
I didn't do this as not to affect the performance of debug builds, although I'm not opposed to adding it. Either way, this function should probably be unsafe?
There was a problem hiding this comment.
Last time I touched these, even introducing inline(always) functions in some of these places had significant impact on performance. This should get a perf run, and ideally also some manual benchmarking.
There was a problem hiding this comment.
Yikes, yep, benchmarks I just ran confirm this. So are they not actually being inlined, or what's going on?
There was a problem hiding this comment.
So we don't need to bother perfbot then?^^
So are they not actually being inlined, or what's going on?
Your guess is as good as mine. One hypothesis we had last time was that inlining happens after some other passes -- so manually inlined code basically is already present earlier in the pipeline and gets simplified better.
You could try to compile your benchmark to LLVM IR with the old and new version of libstd and compare. You'll see that the function did get inlined, but the IR is still vastly different.
There was a problem hiding this comment.
It's unfortunate that functions apparently aren't zero-cost here, but I guess it is what it is.
I turned next_unchecked and next_back_unchecked into macros and that seems to have fixed all the regressions. 🙂 It's hard to say for sure though, every time I run the benchmarks there are a few that change by up to 5% or so in either direction, although it's not always the same ones. It seems like they're just not very stable.
RalfJung
commented
May 13, 2019
For perf:
When I tried, this made a difference. See in particular the discussion starting here. |
bors
commented
May 13, 2019
⌛ Trying commit dde6587388afb05ddf716c97aaa6d8cdfecfae97 with merge a7f658d531f58408d872991a0aad92876b86712c... |
bors
commented
May 13, 2019
☀️ Try build successful - checks-travis |
rust-highfive
commented
May 13, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
timvermeulen
commented
May 13, 2019
@RalfJung Thanks! That's very helpful. Looks like we can't get rid of the macros yet, then. |
RalfJung
commented
May 13, 2019
Let's see what perf has to say, then. @bors try |
bors
commented
May 13, 2019
Implement nth_back for slice::{Iter, IterMut}
Part of #54054.
I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂
I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me.
I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.bors
commented
May 13, 2019
☀️ Try build successful - checks-travis |
RalfJung
commented
May 14, 2019
@rust-timer build e89b9fd |
rust-timer
commented
May 14, 2019
Success: Queued e89b9fd with parent a9ec99f, comparison URL. |
It's not clear to me whether the 0.8% change to |
timvermeulen
commented
May 24, 2019
I also made @bors try |
bors
commented
May 24, 2019
@timvermeulen: 🔑 Insufficient privileges: not in try users |
RalfJung
commented
May 25, 2019
@bors try |
bors
commented
May 25, 2019
Implement nth_back for slice::{Iter, IterMut}
Part of #54054.
I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂
I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me.
I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.bors
commented
May 25, 2019
☀️ Try build successful - checks-travis |
RalfJung
commented
May 25, 2019
@rust-timer build 01fe51e |
rust-timer
commented
May 25, 2019
Success: Queued 01fe51e with parent 315ab95, comparison URL. |
rust-timer
commented
May 25, 2019
Finished benchmarking try commit 01fe51e: comparison url |
timvermeulen
commented
May 25, 2019
This looks better! |
Centril
commented
May 29, 2019
r? @scottmcm |
jonas-schievink
commented
Jun 18, 2019
Triage: Waiting for review by @rust-lang/libs |
scottmcm
commented
Jun 20, 2019
Looks good, thanks @timvermeulen! @bors r+ |
bors
commented
Jun 20, 2019
📌 Commit 97a6c93 has been approved by |
…=scottmcm
Implement nth_back for slice::{Iter, IterMut}
Part of rust-lang#54054.
I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂
I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me.
I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.RalfJung
commented
Jun 20, 2019
@bors rollup- |
RalfJung
commented
Jun 20, 2019
Well that didn't do anything. And it's already been rolled up anyway... whatever^^ |
Part of #54054.
I implemented
nth_backas straightforwardly as I could, and then slightly changednthto matchnth_back. I believe I did so correctly, but please double-check 🙂I also added the helper methods
zst_shrink,next_unchecked, andnext_back_uncheckedto get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me.I noticed the
is_empty!andlen!macros which sole purpose seems to be inlining, according to the comment right above them, but theis_emptyandlenmethods are already marked with#[inline(always)]. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.