Skip to content
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

Optimize ZStream#sliding #7941

Merged
merged 4 commits into from
Mar 24, 2023
Merged

Optimize ZStream#sliding #7941

merged 4 commits into from
Mar 24, 2023

Conversation

adamgfraser
Copy link
Contributor

No description provided.

@adamgfraser adamgfraser changed the title Optimize Chunk#slice Optimize ZStream#sliding Mar 24, 2023
override def slice(from: Int, until: Int): Chunk[A] = {
val start = if (from < 0) 0 else if (from > length) length else from
val end = if (until < start) start else if (until > length) length else until
Chunk.Slice(self, start, end - start)
Copy link
Member

Choose a reason for hiding this comment

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

Not strictly required but it can be a good idea to avoid creating the slice if from = 0, until = end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interestingly this results in about a 20% reduction in the throughput of the stream benchmark, I think due to additional branching that doesn't get optimized. Of course I'm sure there are other cases where you don't actually need to create the slice that would benefit from this.

Copy link
Member

Choose a reason for hiding this comment

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

All right, let's skip it. I was mostly thinking of stack safety in cases where slicing is done recursively based on dynamically computed bounds.

jdegoes
jdegoes previously approved these changes Mar 24, 2023
@jdegoes jdegoes merged commit c3716d1 into zio:series/2.x Mar 24, 2023
@adamgfraser adamgfraser deleted the slice branch March 24, 2023 14:08
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.

None yet

2 participants