Rollup merge of #58122 - matthieu-m:range_incl_perf, r=dtolnay
RangeInclusive internal iteration performance improvement. Specialize `Iterator::try_fold` and `DoubleEndedIterator::try_rfold` to improve code generation in all internal iteration scenarios. This changes brings the performance of internal iteration with `RangeInclusive` on par with the performance of iteration with `Range`: - Single conditional jump in hot loop, - Unrolling and vectorization, - And even Closed Form substitution. Unfortunately, it only applies to internal iteration. Despite various attempts at stream-lining the implementation of `next` and `next_back`, LLVM has stubbornly refused to optimize external iteration appropriately, leaving me with a choice between: - The current implementation, for which Closed Form substitution is performed, but which uses 2 conditional jumps in the hot loop when optimization fail. - An implementation using a `is_done` boolean, which uses 1 conditional jump in the hot loop when optimization fail, allowing unrolling and vectorization, but for which Closed Form substitution fails. In the absence of any conclusive evidence as to which usecase matters most, and with no assurance that the lack of Closed Form substitution is not indicative of other optimizations being foiled, there is no way to pick one implementation over the other, and thus I defer to the statu quo as far as `next` and `next_back` are concerned.
This commit is contained in:
commit
f19bec89d7
3 changed files with 81 additions and 6 deletions
|
@ -334,12 +334,14 @@ pub struct RangeInclusive<Idx> {
|
|||
trait RangeInclusiveEquality: Sized {
|
||||
fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool;
|
||||
}
|
||||
|
||||
impl<T> RangeInclusiveEquality for T {
|
||||
#[inline]
|
||||
default fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool {
|
||||
range.is_empty.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PartialOrd> RangeInclusiveEquality for T {
|
||||
#[inline]
|
||||
fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue