-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Optimize ZStream#sliding #7941
Conversation
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) |
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.
Not strictly required but it can be a good idea to avoid creating the slice if from = 0, until = end.
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.
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.
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.
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.
No description provided.