-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Added collectFirst to Chain and NonEmptyChain #2796
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added collectFirstSome to Chain and NonEmptyChain. Overrided collectF…
…irst and collectFirstSome in the Foldable instances of Chain and NonEmptyChain.
- Loading branch information
commit e78385df3454a13b424332b503150953bb442cdc
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reimplement using
foreachUntil
? The whole purpose of overriding the Foldable one is the performance gain, so I'd rather be sure that it reduces overhead to the minimum.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure that this will give some noticeable performance improvement. I will try to benchmark this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I am curious to see the benchmark
foreachUntil
implementation ofcollectFrist
v.s. the vanilla implementation fromFoldable
usingfoldRight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally find time for the benchmark.
I made a separate branch for benchmarking. Here is the commit with the code of the benchmark.
I removed overrides from the
Foldable
instance to compare the performance of the default implementation ofcollectFirst
/collectFirstSome
from theFoldable
. Also, I addedcollectFirstSome2
with the specialized version ofcollectFirstSome
, based onforeachUntil
and withoutFunction.unlift
.I benchmarked small (size 5), medium (size 100) and large (size 1000000) chains.
I ran benchmarks with the following command:
jmh:run -i 10 -wi 10 -f1 -t1 .*ChainCollectFirst.*
Benchmarks
*Foldable
is the default implementation fromFoldable
.*New
is new implementation from my PRcollectFirstSome2*New
iscollectFirstSome
based onforeachUntil
and withoutFunction.unlift
Results
collectFirst
/collectFirstSome
from my PR is few times faster than defaults for anyChain
size.collectFirstSome
based oncollectFirst
andFunction.unlift
is ~2 times slower thancollectFirstSome
based onforeachUntil
for the small chains.collectFirstSome
based oncollectFirst
andFunction.unlift
has almost same performance ascollectFirstSome
based onforeachUntil
for the medium and large chains.Conclusion
I changed
collectFirstSome
implementation toforeachUntil
. I added a new commit to this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome! thanks so much for this contribution.