-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use an improved eq in FiberRefs
and add shortcut for join
#9100
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
Use an improved eq in FiberRefs
and add shortcut for join
#9100
Conversation
* method shows up in benchmarks, make sure to compile the code with the | ||
* envvar set. | ||
*/ | ||
private def improvedEq[A <: AnyRef](x: A, y: A): Boolean = { |
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.
It's not great, but: eqWithBoxedNumericEquality
?
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.
Done :)
My apologies @ghostdogpr, I ended up making some final adjustments after your review:
|
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.
Excellent work, as always! Love the huge foreachPar speedup. ❤️
One of the things I didn't account for in #8989 is that
eq
on boxed primitives returns false even if the underlying integer is the same 🫠. The fix is rather simple; typecheck the value and if it's ajava.lang.Number
then unbox it and compare it (viaBoxesRunTime.equalsNumObject
.While I was doing this, I thought to also do the following:
improvedEq
produces the same outcome as==
(note that this assertion does not exist in the published artifacts!).FiberRefs
which are equal according toeq
. This is a very common case especially when we doZIO.foreachPar
, since in most cases we won't be modifying any of the FiberRefs in any of the effects run in parallel. Therefore,inheritAll
then becomes much cheaper, which overall improves the performance offoreachPar
quite substantially:series/2.x
PR
Note that in some rare cases, the
ZEnvironment.Patch.diff
will return a Patch that when applied, it will result having the same services in the environment. To avoid this, I added a guard against this by checking that the resulting ZEnvironment is indeed different (as determined by==
). I think that since our equals method onZEnvironment
is fairly well optimized, I'm thinking it's better not to risk destroying theFiberRefs
optimizations and perform this check. Thoughts?