Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kyri-petrou
Copy link
Contributor

No need for it to be lazy, it only adds overhead

@kyri-petrou kyri-petrou changed the title Make Parallelism non-lazy Make ZIO.Parallelism non-lazy Sep 4, 2025
@kyri-petrou
Copy link
Contributor Author

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 and proxied it in ZIO

guizmaii
guizmaii previously approved these changes Sep 4, 2025
hearnadam
hearnadam previously approved these changes Sep 4, 2025
FiberRef.unsafe.makeSupervisor(Runtime.defaultSupervisor)(Unsafe.unsafe)

private[zio] val parallelism: FiberRef[Option[Int]] =
FiberRef.unsafe.make[Option[Int]](None)(Unsafe)
Copy link
Collaborator

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?

Copy link
Contributor Author

@kyri-petrou kyri-petrou Sep 5, 2025

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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]>
@kyri-petrou kyri-petrou dismissed stale reviews from hearnadam and guizmaii via 4c0ae08 September 5, 2025 16:30
*/
final lazy val Parallelism: FiberRef[Option[Int]] =
FiberRef.unsafe.make[Option[Int]](None)(Unsafe)
def Parallelism: FiberRef[Option[Int]] =
Copy link
Collaborator

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?

Copy link
Contributor Author

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 (!?) 😞

@kyri-petrou kyri-petrou merged commit 4d67c2e into zio:series/2.x Sep 8, 2025
19 checks passed
@kyri-petrou kyri-petrou deleted the non-lazy-parallelism branch September 8, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants