Uh oh!
There was an error while loading. Please reload this page.
Insurance policy in case iter.size_hint() lies. - #65749
Conversation
Centril
commented
Oct 24, 2019
@bors try @rust-timer queue |
rust-timer
commented
Oct 24, 2019
Awaiting bors try build completion |
bors
commented
Oct 24, 2019
⌛ Trying commit 256335b with merge bc4dafa90d4ba113c682edfe266ea94a0e2fbc2f... |
bors
commented
Oct 24, 2019
☀️ Try build successful - checks-azure |
rust-timer
commented
Oct 24, 2019
Queued bc4dafa90d4ba113c682edfe266ea94a0e2fbc2f with parent 4a8c5b2, future comparison URL. |
| f(&[t0, t1]) | ||
| } | ||
| (0, Some(0)) => { | ||
| assert!(iter.next().is_none()); |
There was a problem hiding this comment.
If it matters this could be written without unwrap's or asserts.
let a = match iter.next(){None => returnOk(f(&[])),Some(a) => a?,};let b = match iter.next(){None => returnOk(f(&[a])),Some(b) => b?,};let c = match iter.next(){None => returnOk(f(&[a, b])),Some(c) => c?,};letmut vec:SmallVec<[_;8]> = SmallVec::with_capacity(iter.size_hint().0 + 3);
vec.push(a);
vec.push(b);
vec.push(c);for result in iter {
vec.push(result?);}Ok(f(&vec))There was a problem hiding this comment.
Nice! OTOH, the original order of the match was chosen by @nnethercote to reflect the frequency of the cases.
There was a problem hiding this comment.
@RalfJung Should we perf test this variant?
There was a problem hiding this comment.
The vec construction could be more concise, e.g. using extend. And I would use t0, t1, t2 instead of a, b, c. And the comment needs updating. Otherwise, fine by me to use this form if the perf isn't hurt.
There was a problem hiding this comment.
extend would be better but there isn't a way in std to extend from a Result iterator so you need a workaround like https://github.com/mitsuhiko/redis-rs/blob/418512bf9171589b814da4c5ecb500e8747781e0/src/parser.rs#L21-L54
rust-timer
commented
Oct 24, 2019
Finished benchmarking try commit bc4dafa90d4ba113c682edfe266ea94a0e2fbc2f, comparison URL. |
Centril
commented
Oct 24, 2019
Perf looks like noise / possibly an improvement. |
Centril
commented
Oct 25, 2019
@bors try @rust-timer queue |
rust-timer
commented
Oct 25, 2019
Awaiting bors try build completion |
bors
commented
Oct 25, 2019
Insurance policy in case `iter.size_hint()` lies. Follow up to https://github.com/rust-lang/rust/pull/64949/files#r334235076. (If the perf impact is bad we can use `debug_assert!` instead.) The good news is that the UI tests pass locally so `iter.size_hint()` seems to be honest *thus far*. On the other hand, with the status quo we do not have an insurance policy should that change in some case. This is problematic because a) this could possibly make some program be accepted which shouldn't, b) the compiler itself could have memory unsafety if the correctness of the iterator is assumed in `unsafe { ... }` code (even though the blame lies with the `unsafe { ... }` block in question.) r? @RalfJung cc @nnethercote
bors
commented
Oct 25, 2019
☀️ Try build successful - checks-azure |
rust-timer
commented
Oct 25, 2019
Queued 2beb6a3 with parent 10a52c2, future comparison URL. |
rust-timer
commented
Oct 25, 2019
Finished benchmarking try commit 2beb6a3, comparison URL. |
@nnethercote Thoughts on ^---? It looks like a slight regression to me. |
nnethercote
commented
Oct 25, 2019
Let's go with the first one! :) |
mati865
commented
Oct 25, 2019
I think Clippy even has lint against: for result in iter {
vec.push(result?);}IIRC this performs poorly and could be main reason of this regression. |
lies, underreporting the number of elements.
c85bfc5 to
dfcfca2CompareCentril
commented
Oct 25, 2019
Dropped the second commits in favor of the first solution which had clean perf; @bors r=RalfJung |
bors
commented
Oct 25, 2019
📌 Commit dfcfca2 has been approved by |
Insurance policy in case `iter.size_hint()` lies. Follow up to https://github.com/rust-lang/rust/pull/64949/files#r334235076. (If the perf impact is bad we can use `debug_assert!` instead.) The good news is that the UI tests pass locally so `iter.size_hint()` seems to be honest *thus far*. On the other hand, with the status quo we do not have an insurance policy should that change in some case. This is problematic because a) this could possibly make some program be accepted which shouldn't, b) the compiler itself could have memory unsafety if the correctness of the iterator is assumed in `unsafe { ... }` code (even though the blame lies with the `unsafe { ... }` block in question.) r? @RalfJung cc @nnethercote
Rollup of 7 pull requests Successful merges: - #63810 (Make <*const/mut T>::offset_from `const fn`) - #65705 (Add {String,Vec}::into_raw_parts) - #65749 (Insurance policy in case `iter.size_hint()` lies.) - #65799 (Fill tracking issue number for `array_value_iter`) - #65800 (self-profiling: Update measureme to 0.4.0 and remove non-RAII methods from profiler.) - #65806 (Add [T]::as_ptr_range() and [T]::as_mut_ptr_range().) - #65810 (SGX: Clear additional flag on enclave entry) Failed merges: r? @ghost
Insurance policy in case `iter.size_hint()` lies. Follow up to https://github.com/rust-lang/rust/pull/64949/files#r334235076. (If the perf impact is bad we can use `debug_assert!` instead.) The good news is that the UI tests pass locally so `iter.size_hint()` seems to be honest *thus far*. On the other hand, with the status quo we do not have an insurance policy should that change in some case. This is problematic because a) this could possibly make some program be accepted which shouldn't, b) the compiler itself could have memory unsafety if the correctness of the iterator is assumed in `unsafe { ... }` code (even though the blame lies with the `unsafe { ... }` block in question.) r? @RalfJung cc @nnethercote
Rollup of 6 pull requests Successful merges: - #65705 (Add {String,Vec}::into_raw_parts) - #65749 (Insurance policy in case `iter.size_hint()` lies.) - #65799 (Fill tracking issue number for `array_value_iter`) - #65800 (self-profiling: Update measureme to 0.4.0 and remove non-RAII methods from profiler.) - #65806 (Add [T]::as_ptr_range() and [T]::as_mut_ptr_range().) - #65810 (SGX: Clear additional flag on enclave entry) Failed merges: r? @ghost
Follow up to https://github.com/rust-lang/rust/pull/64949/files#r334235076.
(If the perf impact is bad we can use
debug_assert!instead.)The good news is that the UI tests pass locally so
iter.size_hint()seems to be honest thus far.On the other hand, with the status quo we do not have an insurance policy should that change in some case. This is problematic because a) this could possibly make some program be accepted which shouldn't, b) the compiler itself could have memory unsafety if the correctness of the iterator is assumed in
unsafe { ... }code (even though the blame lies with theunsafe { ... }block in question.)r? @RalfJung
cc @nnethercote