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

Skip to content

Conversation

@kyri-petrou
Copy link
Contributor

I noticed that Queue#shutdown was quite unoptimized while looking at a different PR.

At the moment Queue#shutdown is quite heavy for the calling thread, as it involves a lot of ZIO's in addition to completing Promises in parallel unnecessarily. With this PR we avoid all of this which should make queue shutdowns a lot faster. While most workflows won't see much of a performance benefit from this change, certain workflows that rely on creation of queues for streams will definitely benefit from these changes.

@kyri-petrou kyri-petrou requested a review from guizmaii April 9, 2025 15:28
else {
val as = unsafePollAll(queue)
if (as.nonEmpty) {
if (!as.isEmpty) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I noticed a few nonEmpty calls. This is a micro-optimization as isEmpty is implemented directly on Chunk but nonEmpty requires an interface method dispatch which is very slow

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to override knownSize in Chunk.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def surplusSize: Int

def shutdown(implicit trace: Trace): UIO[Unit]
def shutdown(fiberId: FiberId)(implicit trace: Trace, unsafe: Unsafe): Unit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be protected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, since it's called by Queue. But it's OK because Strategy is a private class

@kyri-petrou kyri-petrou merged commit f5e6ff6 into zio:series/2.x Apr 10, 2025
18 checks passed
@kyri-petrou kyri-petrou deleted the optimize-queue-shutdown branch April 10, 2025 06:24
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