Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
select_early_exit
creates a stream that produces elements while either substream contains elements, and terminates when either substream runs out of elements.Previous work
#1881
#1422
Benchmarks:
Performance hit: +8.8%.
The
select_streams
benchmark is quite contrived, using long streams nested deeply under multipleSelect
s to produce statistically significant results. As such, I'm happy with the +8.8% performance hit, and would prefer it over a separate version ofSelectWithStrategy
just for early exit.Side note, if you leave out the
#[inline]
over theis_finished
function, you get1,830,713ns/iter
, or a +71.8% performance hit.I've tried to specialize
SelectWithStrategy
over an exit strategy trait in this branch, but surprisingly, got a small performance hit.I can't say for sure what's going on, but my best guess is that the performance difference between this branch and the one linked above is due to a layout change, rather than how the logic is encoded.
It would be possible to use something like
stabilizer
to know for sure, but I doubt we actually want to go that deep on this.