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

ZIO Runtime System Improvements (2.1 candidate) #8582

Merged
merged 20 commits into from Dec 27, 2023

Conversation

jdegoes
Copy link
Member

@jdegoes jdegoes commented Dec 22, 2023

I extracted a smaller subset of changes from my mega Loom PR that will be useful to all ZIO users, whether or not they are using Loom. In addition, I went far beyond the initial improvements to the runtime system, implementing a hybrid engine that prefers synchronous execution but can do asynchronous execution at almost no cost beyond a gen 2 runtime, and switching from exceptions for errors to Exit values, which turns out to result in slightly less boxing given the other changes.

The code is much cleaner and easier to understand and there are probably a few more changes I will push over the weekend before it's ready to merge, but I want to get it on CI to ensure the build and all tests are passing on all platforms.

Note that fork/join performance is still in need of substantial optimization. Although medium to long-lived fibers will not benefit from this work, a lot of benchmarks fork a single effect or so, and so the overhead of fork/join is noticeable on these benchmarks. I am not planning on doing that work as part of this PR as there is no single culprit, just a lot of little micro-optimizations everywhere.

[info] Benchmark                                 (size)   Mode  Cnt       Score      Error  Units
[info] NarrowFlatMapBenchmark.catsNarrowFlatMap    1000  thrpt   10  216200.239 ± 4567.436  ops/s
[info] NarrowFlatMapBenchmark.zioNarrowFlatMap     1000  thrpt   10  397569.072 ± 4533.070  ops/s

[info] Benchmark                               (depth)   Mode  Cnt      Score     Error  Units
[info] BroadFlatMapBenchmark.catsBroadFlatMap       20  thrpt   10  11453.728 ± 293.411  ops/s
[info] BroadFlatMapBenchmark.zioBroadFlatMap        20  thrpt   10  14997.588 ± 303.544  ops/s

[info] Benchmark                    (depth)   Mode  Cnt         Score       Error  Units
[info] UnsafeRunBenchmark.cioLeft         1  thrpt   10    273214.539 ±  9362.123  ops/s
[info] UnsafeRunBenchmark.cioLeft         2  thrpt   10    269689.042 ±  6052.566  ops/s
[info] UnsafeRunBenchmark.cioLeft         4  thrpt   10    275378.796 ±  2881.704  ops/s
[info] UnsafeRunBenchmark.cioLeft         8  thrpt   10    278456.788 ±  4085.332  ops/s
[info] UnsafeRunBenchmark.cioRight        1  thrpt   10    275732.511 ±  5215.037  ops/s
[info] UnsafeRunBenchmark.cioRight        2  thrpt   10    272349.000 ±  3111.751  ops/s
[info] UnsafeRunBenchmark.cioRight        4  thrpt   10    269357.437 ±  3917.978  ops/s
[info] UnsafeRunBenchmark.cioRight        8  thrpt   10    278139.126 ±  6986.661  ops/s
[info] UnsafeRunBenchmark.zioLeft         1  thrpt   10  10969100.583 ± 23350.643  ops/s
[info] UnsafeRunBenchmark.zioLeft         2  thrpt   10  10950533.110 ± 53321.202  ops/s
[info] UnsafeRunBenchmark.zioLeft         4  thrpt   10  10877998.123 ± 70289.707  ops/s
[info] UnsafeRunBenchmark.zioLeft         8  thrpt   10  12618324.349 ± 59154.389  ops/s
[info] UnsafeRunBenchmark.zioRight        1  thrpt   10  11289681.825 ± 54609.222  ops/s
[info] UnsafeRunBenchmark.zioRight        2  thrpt   10  10948475.472 ± 60844.859  ops/s
[info] UnsafeRunBenchmark.zioRight        4  thrpt   10  12605913.309 ± 82654.252  ops/s
[info] UnsafeRunBenchmark.zioRight        8  thrpt   10  12582028.228 ± 82626.749  ops/s

[info] Benchmark                                  Mode  Cnt     Score    Error  Units
[info] ForEachBenchmark.catsForEachFork          thrpt   10   252.644 ±  4.225  ops/s
[info] ForEachBenchmark.catsForEachForkAwait     thrpt   10   109.672 ±  9.358  ops/s
[info] ForEachBenchmark.catsForEachIncrementRef  thrpt   10   483.049 ± 11.623  ops/s
[info] ForEachBenchmark.catsForkEachUnit         thrpt   10   527.591 ±  4.439  ops/s
[info] ForEachBenchmark.zioForEachFork           thrpt   10    38.471 ±  2.227  ops/s
[info] ForEachBenchmark.zioForEachForkAwait      thrpt   10    15.299 ±  8.026  ops/s
[info] ForEachBenchmark.zioForEachIncrementRef   thrpt   10  2805.665 ± 73.516  ops/s
[info] ForEachBenchmark.zioForEachUnit           thrpt   10  7201.408 ± 65.043  ops/s

adamgfraser
adamgfraser previously approved these changes Dec 23, 2023
@jdegoes
Copy link
Member Author

jdegoes commented Dec 27, 2023

@adamgfraser Ready for final review

@jdegoes jdegoes merged commit 0304398 into zio:series/2.x Dec 27, 2023
20 checks passed
@jdegoes jdegoes deleted the rts-part-1 branch December 27, 2023 20:55
adamgfraser added a commit that referenced this pull request Jan 2, 2024
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