-
-
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
Drastically speed up Monoid[Map[K, V]] instance. #1300
Conversation
This commit fixes a number of problems I introduced with cats-kernel. 1. Map's monoid was not overriding combineAll 2. It was also doing the wrong thing for combine 3. Monoid should have overridden combineAllOption The performance for map's `combine` is 150x faster after this commit, and `combineAll` is 780x faster. Rather than focusing on how good these speed ups are, I want to apologize for how bad the implementations were previously. The new `combine` is competitive with other implementations, and `combineAll` is about x5 faster than the equivalent code using combine. (All figures using before/after numbers for the given benchmark.) Thanks to Adelbert and Travis for noticing this problem. Also thanks to Travis for producing this benchmark! Finally, thanks to Oscar for helping me look at and fix this issue.
This fixes #1290. |
👍 |
👍, thanks! |
result | ||
} | ||
|
||
def wrapMutableMap[K, V](m: mutable.Map[K, V]): Map[K, V] = |
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.
if you remove this, it becomes unusable from the outside. That was the reason for it, I think, to allow using it from say algebra
.
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.
Ah, right! I'll add them back so we can use them in Algebra (and beyond).
Since we made WrappedMutableMap private to the kernel, we need something like this so that Algebra, Spire, Algebird, etc. can all take advantage of this basic pattern.
Current coverage is 90.76% (diff: 100%)@@ master #1300 diff @@
==========================================
Files 234 234
Lines 3377 3380 +3
Methods 3323 3323
Messages 0 0
Branches 52 55 +3
==========================================
+ Hits 3065 3068 +3
Misses 312 312
Partials 0 0
|
Two sign-offs, I'm merging. |
This commit fixes a number of problems I introduced with cats-kernel.
The performance for map's
combine
is 150x faster after this commit,and
combineAll
is 780x faster. Rather than focusing on how goodthese speed ups are, I want to apologize for how bad the
implementations were previously. The new
combine
is competitive withother implementations, and
combineAll
is about x5 faster than theequivalent code using combine.
(All figures using before/after numbers for the given benchmark.)
Thanks to Adelbert and Travis for noticing this problem. Also thanks
to Travis for producing this benchmark! Finally, thanks to Oscar for
helping me look at and fix this issue.