-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Optimize Scope-related methods #9372
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
Conversation
| def scopeWith[R, E, A](f: Scope => ZIO[R, E, A])(implicit trace: Trace): ZIO[R with Scope, E, A] = | ||
| ZIO.serviceWithZIO[Scope](f) | ||
| FiberRef.currentEnvironment.getWith(env => f(env.unsafe.getScope(Unsafe))) |
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.
This is 'safe' because of with Scope?
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.
Yes. It's not any different than what was happening previously. The only thing that is making things "safe" is that the Scope is that Scope needs to be erased from R. Unsafely casting the type to remove the Scope from the requirement will cause a runtime error (both previously and now)
# Conflicts: # core/shared/src/main/scala/zio/ZEnvironment.scala
|
I wonder if it improves the streaming benchmarks 😇 |
|
@regiskuckaertz there seems to be a 5-10% improvement in the series/2.x PR: |
This PR (micro)-optimizes various methods related to usage of
Scopein ZIO. The main optimizations come from reducing the number of flatMaps and unnecessary object creation / Long boxing when creating / closing a forkedScope(which happens a lot particularly inZStreammethods). It also optimizes Scope access (viaZIO.scope/ZIO.scopeWith) by adding a new accessor method to ZEnvironment for retrieving the Scope within it, bypassing the need to check the service tag.