-
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
Make concatenation of empty chunks 600 times faster #7396
Make concatenation of empty chunks 600 times faster #7396
Conversation
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.
Looks like just needs a fix for one linting error!
Fixed |
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.
Thanks!
@RafalSumislawski I think your benchmark results are reversed |
@shawjef3 no, why? These are ops/s (higher == better). 1.768 ops/s before this improvement. 1144.024 ops/s after. |
@RafalSumislawski jeez right! I do my own benchmarks with the inverse unit so this always gets me. |
Adding if (isEmpty) {
that
} else if (that.isEmpty) {
self
} else { to the beginning of Before [info] Benchmark (size) Mode Cnt Score Error Units
[info] ChunkConcatBenchmarks.leftConcat0 10000 thrpt 5 1463.820 ± 13.910 ops/s
[info] ChunkConcatBenchmarks.rightConcat0 10000 thrpt 5 1459.460 ± 45.090 ops/s After [info] Benchmark (size) Mode Cnt Score Error Units
[info] ChunkConcatBenchmarks.leftConcat0 10000 thrpt 5 75810.357 ± 1133.715 ops/s
[info] ChunkConcatBenchmarks.rightConcat0 10000 thrpt 5 67140.985 ± 825.722 ops/s |
Sorry I missed that this was closed. I'll make another PR. |
* Fix Gen.instant (#7325) * Make concatenation of empty chunks 600 times faster (#7396) * Extend benchmark coverage of Chunk concatenation * Improve performance of concatenation of empty Chunks * replace unused identifier with _ * Improve Chunk concatenation performance when either chunk is empty. (#7399) * Update things for Scala Native (still no running tests) (#7409) * Scala Native: run tests * Native: Run scala-native-loop in OneShot#get * Native: Test / fork := false * ci.yaml: testPlatforms on Scala 3 * ci.yaml: testPlatforms 180 min timeout * ci.yaml: testPlatforms 360 min timeout * ci.yaml: testPlatforms on Scala 3 * Update versions * Update versions * Update munit * Update things for Scala Native (still no running tests) * Update * Scala 2.12.16, 2.13.8 * fix merge Co-authored-by: LUC DUZAN <strokyl@users.noreply.github.com> Co-authored-by: Rafał Sumisławski <rafal.sumislawski@gmail.com> Co-authored-by: shawjef3 <shawjef3@gmail.com>
Concatenation of empty Chunks is very slow. This is caused by
Empty match {case Empty => ???}
being an expensive operation. Usually pattern machine on case object is very cheap, because their defaultequals
is cheap. Not in this case.Empty
inheritsequals
from Chunk.The focus of this PR is to improve the performance of concatenation of empty chunks. In addition to that I've extended the benchmarks. There's more that can be done, but ensuring that there are no performance regressions takes a lot of time designing benchmarks and running them for hours, so I scaled the scope of the PR down to this very simple change which ensures that concatenation of empty chunks is as fast as concatenation of non-empty chunks.
This PR extends benchmark coverage of Chunk concatenation.
Benchmarks
Pay attention to the improvement in the leftConcat0 and rightConcat0 benchmarks. No regressions in other benchmarks.
Before
After
Side note: This should significantly improve performance of
ZValidated.validateAll
(zio-prelude
) and other operations onZValidated
, because concatenation of often empty Chunks of logs is involved in these operations.