-
Notifications
You must be signed in to change notification settings - Fork 601
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
Chunk - Optimise Flatten implementation. #3190
Conversation
We can make a similar optimization here? fs2/core/shared/src/main/scala/fs2/Chunk.scala Lines 1173 to 1174 in f5a4d11
|
f5a4d11
to
95e5762
Compare
I'm not convinced this one is worth the gains. Can we benchmark it? |
Sure. I hope that it is not too "dirty" for the optimisation it gains (which is at least two objects per chunk). Is the worry that it may not be that frequent a case? |
Yeah, I'm concerned we're inlining implementations here without proof that the allocations matter. I don't want to put too much faith in to things like escape analysis, but also want to ensure any code duplication / inlining is justified with benchmarks showing the improvements actually matter in real use cases. |
cc9201e
to
91244e4
Compare
As an update, I have moved the "inlined" implementation to a |
I have pushed a file with a benchmark for flatten, with different parameters of number of chunks to flatten and size of each chunk. Running it with the command
Focusing on the
And these are the results with the changes in this PR:
The first parameter is the size of the chunk, and the second one is the number of chunks. In all cases the total number of allocations is reduced by up to a third or more than half. |
@mpilquist Let me know if there are any further benchmarks that can be run. |
Benchmark looks good, though I'm still a bit concerned about chasing allocation rate improvements like this. What type of application would benefit from this change? |
Flattening chunks could be useful in the context of using |
@mpilquist What is your verdict on this PR? Merge? Close? Worthy improvement? Would rather seek a stronger optimisation? |
I'm good with merging. Can we inline |
The current flatten performs one Chunk.Queue insertion per source chunk, which means it creates a new "Chunk.Queue" object and one "Queue" object for each one. Instead, we can avoid those objects and use a Queue- builder.
No, because the constructor of |
The current flatten performs one Chunk.Queue insertion per source chunk, which means it creates a new "Chunk.Queue" object and one "Queue" object for each one. Instead, we can avoid those objects and use a Queue- builder.