-
Couldn't load subscription status.
- Fork 1.4k
Make ZIO.Parallelism non-lazy
#10144
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
|
Seems there was a class-loading issue if we made it into a val and kept it in the ZIO companion object, so I moved it to |
| FiberRef.unsafe.makeSupervisor(Runtime.defaultSupervisor)(Unsafe.unsafe) | ||
|
|
||
| private[zio] val parallelism: FiberRef[Option[Int]] = | ||
| FiberRef.unsafe.make[Option[Int]](None)(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.
Could we use a negative number to represent unbounded?
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 think it might end up being worse due to unboxing (and then boxing) of the not defined case (i.e., -1). If we're going to optimize it, it might be better to have a specialized OptionInt to avoid boxing / unboxing of the Int.
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.
Actually we'd have an issue with binary compatibility since ZIO.Parallelism was public.
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 was suggesting:
private[zio] val parallelism: FiberRef[java.lang.Integer] =
FiberRef.unsafe.make[java.lang.Integer](-1)(Unsafe)You can then have a method to map to the optional variant which of course can be deprecated...
However, I understand if this is more than you want to take on.
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.
We don't have a way to map / contramap a FiberRef unfortunately. Let's potentially tackle this at a later stage after we release with ZIO.Parallelism deprecated
Co-authored-by: Adam Hearn <[email protected]>
| */ | ||
| final lazy val Parallelism: FiberRef[Option[Int]] = | ||
| FiberRef.unsafe.make[Option[Int]](None)(Unsafe) | ||
| def Parallelism: FiberRef[Option[Int]] = |
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 make this deprecated + package private?
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.
Unfortunately making it package-private is not binary compatible in Scala 2.13 as the generated method becomes non-static (!?) 😞
No need for it to be lazy, it only adds overhead