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

Pattern-match on types instead of tags in ZPure#runAll #1251

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

kyri-petrou
Copy link
Contributor

This PR optimizes the performance of ZPure by pattern matching on implementation types over tags.

While the reasoning on why this is more performant is still not very clear to me, I've noticed similar issues in Caliban and seem to be related to how the JVM optimizes (or in better terms, fails to optimize) interface dispatches. I've also noticed that ZIO 1.x used the same pattern matching mechanism (via tags), but that was changed to type-based pattern matching in ZIO 2.x

With the changes in this PR, we get a ~20% performance improvement when running ZPure effects.

// Before
[info] Benchmark                                 (size)   Mode  Cnt     Score   Error  Units
[info] ForEachBenchmarks.zioForEachZPure         100000  thrpt    5   960.111 ± 8.891  ops/s
[info] ForEachBenchmarks.zioForEach_ZPure        100000  thrpt    5  1378.970 ± 9.880  ops/s

// After
[info] Benchmark                                 (size)   Mode  Cnt     Score    Error  Units
[info] ForEachBenchmarks.zioForEachZPure         100000  thrpt    5  1132.690 ± 36.274  ops/s
[info] ForEachBenchmarks.zioForEach_ZPure        100000  thrpt    5  1683.133 ± 17.517  ops/s

@kyri-petrou kyri-petrou requested a review from a team as a code owner February 1, 2024 03:51
@adamgfraser adamgfraser merged commit b3dde02 into zio:series/2.x Feb 1, 2024
19 checks passed
@kyri-petrou kyri-petrou deleted the optimize-zpure-execution branch February 1, 2024 04:33
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.

2 participants