-
-
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
Reconsider the use of fold in Validated #1951
Comments
👍 , it's the reasoning we took in #1289 as well |
What if |
+1
In general core library code in my view should have a nice API but then be
implemented as efficiently as possible. I’d love to see us use the highest
performance approach we can find.
On Thu, Oct 5, 2017 at 21:10 Julien Richard-Foy ***@***.***> wrote:
What if fold is an abstract method in Validated and implemented in Invalid
and Valid? (we would trade pattern matching for dynamic dispatch)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1951 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEJdkvM7HPVPALDnEoC2dUPjC-cRCTlks5spdJbgaJpZM4PwDNP>
.
--
P. Oscar Boykin, Ph.D. | http://twitter.com/posco | http://pobox.com/~boykin
|
It will be interesting to benchmark @julienrf 's abstract |
@julienrf @kailuowang I don't think pattern matching is the real culprit here—it's more the overhead of the functions. Making
…but there's no measurable difference on 2.11 and the allocation situation is the same on both. |
functions, I've always heard, are very hard on the jit due to them being megamorphic. So, one of the best optimizations you can often do in scala is remove a function and replace with literal code that the JIT won't skip over. I would love if this could be solved in the future with dotty linker, or changes to the JIT to better handle lambdas (maybe java will start to care about this now that they have lambdas). |
How can we apply that in our context? |
@julienrf I think just rewriting Users can decide whether for their own cases which approach they want. For example I use |
A lot of the method implementations in
Validated
are extremely inefficient, which isn't ideal for projects like circe that rely on it extensively and are aiming for reasonable performance. For example, given this simplified definition (whereeqF
is the current===
andeqP
is a lightly optimized version):And a benchmark like this:
The pattern matching implementation gets over four times the throughput on 2.12:
The situation is even worse on 2.11, where the difference is a little larger and the
fold
version also involves a lot of unnecessary allocations:For most use cases these differences are unlikely to matter at all, but it seems like a shame to impose this extra cost on everyone just for the sake of slightly more concise implementations.
(There are similar issues in
IndexedStateT
, etc., butValidated
is the one piece I personally really care that much about, because of how it affects circe.)The text was updated successfully, but these errors were encountered: