-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Stream par optimizations a3 #9919
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
Open
eyalfa
wants to merge
6
commits into
zio:series/2.x
Choose a base branch
from
eyalfa:stream_par_optimizations_a3
base: series/2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 5d4d9fb Merge: dd9a4d4 d2bc5fd Author: Eyal Farago-Hagag <eyal.farago@gmail.com> Date: Sat May 31 10:50:23 2025 +0300 Merge branch 'series/2.x' into stream_par_optimizations_a3 commit dd9a4d4 Author: Eyal Farago-Hagag <eyal.farago@gmail.com> Date: Sat May 31 10:48:54 2025 +0300 stream_par_optimizations_a3: fmt commit 1776963 Author: Eyal Farago-Hagag <eyal.farago@gmail.com> Date: Fri May 30 19:41:59 2025 +0300 stream_par_optimizations_a3: fix an elusive race condition, fibers may be interrupted BEFORE starting, and actually never started, resulting with a hung fiber commit 01eca4e Author: Eyal Farago-Hagag <eyal.farago@gmail.com> Date: Fri May 30 17:34:28 2025 +0300 stream_par_optimizations_a3: fix one more issue... (99 remaining..) commit c455134 Author: Eyal Farago-Hagag <eyal.farago@gmail.com> Date: Fri May 30 15:34:35 2025 +0300 stream_par_optimizations_a3: use the light semaphore for the ordered version as well commit 56f57fe Author: Eyal Farago-Hagag <eyal.farago@gmail.com> Date: Fri May 30 11:44:28 2025 +0300 stream_par_optimizations_a2: remove View import which is broken in scala 2.12, optimize imports, fmt commit 3b9f217 Merge: e57471d 29b3055 Author: Eyal Farago-Hagag <eyal.farago@gmail.com> Date: Fri May 30 11:24:39 2025 +0300 Merge branch 'series/2.x' into stream_par_optimizations_a2 commit e57471d Author: Eyal Farago-Hagag <efaragohagag@zscaler.com> Date: Thu May 29 15:48:24 2025 +0300 stream_par_optimizations_a2: fmt commit c9bcc82 Author: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> Date: Thu May 29 01:17:27 2025 +0000 Update zio-http to 3.3.2 (zio#9905) Co-authored-by: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> commit 91fb5c5 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Wed May 28 13:40:31 2025 -0700 fix(deps): update tailwindcss monorepo to v4.1.8 (zio#9904) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit 207a2d0 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu May 29 00:11:32 2025 +1000 fix(deps): update dependency @zio.dev/zio-http to v3.3.2 (zio#9903) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit bb2de19 Author: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> Date: Wed May 28 10:48:50 2025 +1000 Update zio-http to 3.3.1 (zio#9897) Co-authored-by: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> commit db4df92 Author: kyri-petrou <67301607+kyri-petrou@users.noreply.github.com> Date: Tue May 27 20:58:54 2025 +0300 Rollback update to `sbt-ci-release` (zio#9894) commit a9ea879 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Tue May 27 09:54:26 2025 -0700 fix(deps): update dependency @zio.dev/zio-http to v3.3.1 (zio#9892) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit 29e7cfd Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Tue May 27 09:31:18 2025 -0700 chore(deps): update dependency @types/react to v19.1.6 (zio#9891) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit b099630 Author: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> Date: Mon May 26 19:10:18 2025 +0300 Update sbt-ci-release to 1.11.0 (zio#9885) Co-authored-by: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> commit 7a4704a Author: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> Date: Fri May 23 18:02:25 2025 -0700 Update zio-http to 3.3.0 (zio#9884) Co-authored-by: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com> commit be2cf76 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Wed May 21 11:03:43 2025 -0700 fix(deps): update dependency @zio.dev/zio-http to v3.3.0 (zio#9879) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit 40c16ac Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Wed May 21 10:17:40 2025 -0700 chore(deps): update dependency @types/react to v19.1.5 (zio#9876) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit f7b2a19 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Mon May 19 10:16:48 2025 -0700 fix(deps): update dependency @zio.dev/zio-schema to v1.7.2 (zio#9873) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit b2bbd09 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Fri May 16 08:06:45 2025 -0600 fix(deps): update dependency @zio.dev/zio-schema to v1.7.1 (zio#9865) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit 1362c98 Author: kyri-petrou <67301607+kyri-petrou@users.noreply.github.com> Date: Thu May 15 20:59:36 2025 -0600 Ignore failing Cause test (zio#9863) commit 2f8bc64 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu May 15 16:41:45 2025 +0000 fix(deps): update tailwindcss monorepo to v4.1.7 (zio#9861) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit f544529 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Tue May 13 14:52:11 2025 +1000 chore(deps): update dependency @types/react to v19.1.4 (zio#9856) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit 19f6dd4 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat May 10 14:49:56 2025 -0600 fix(deps): update dependency @zio.dev/zio-json to v0.7.43 (zio#9852) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit bbc9846 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Fri May 9 14:44:51 2025 -0700 fix(deps): update tailwindcss monorepo to v4.1.6 (zio#9849) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit 68ff3b5 Author: Andrzej Ressel <github@andrzejressel.pl> Date: Tue May 6 16:59:36 2025 +0200 Replace <:<[R0 & out, R] with proper proof (zio#9840) * Reapply "Replace <:<[R0 & Any, R] with proper proof" This reverts commit 52b5db8. * Fix order of operations * Replace throw with errorAndAbort * Inline given commit f41354e Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Tue May 6 06:47:06 2025 -0700 chore(deps): update dependency @types/react to v19.1.3 (zio#9841) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit 291c39e Author: Georgi Krastev <joro.kr.21@gmail.com> Date: Tue May 6 11:43:28 2025 +0300 Extend causes in the Exit.getOrThrow* methods with stack traces (zio#9386) * Extend causes in the Exit.getOrThrow* methods with stack traces The idea is that most users call those methods in interop code and since they are leaving the ZIO runtime, they need a stack trace. Also override `printStackTrace` in `FiberFailure` by delegating to a new `Cause.prettyPrintWith` method which allows for a custom `println` function. This is necessary because the original method uses the private `stackTrace` field, not `getStackTrace`. Updated `Cause` to remove the "Exception in thread" part as this shouldn't be part of the exception `toString`, it's added later and was causing it to be printed twice. Last thing to node is that I didn't change `FiberFailure.toString` for caution of breaking user code but it's not in line with Java exceptions, which don't include the stack trace in their `toString`. * Extract unfoldPull * Fix broken tests * Add tests for getOrThrow stack traces * Test entire traces in StackTracesSpec * Move unfoldPull to steam package object Rename `prettyPrintWith` argument, make it `private[zio]` commit 141211d Author: Andrzej Ressel <github@andrzejressel.pl> Date: Mon May 5 08:39:39 2025 +0200 Replace <:<[R0 & Any, R] with <:<[R0 & out, R] (zio#9838) * Replace <:<[R0 & Any, R] with <:<[R0 & out, R] * Replace <:<[R0 & Any, R] with proper proof * Revert "Replace <:<[R0 & Any, R] with proper proof" This reverts commit 4dbeab8. commit 5932fbc Author: Eyal Farago-Hagag <efaragohagag@zscaler.com> Date: Thu May 29 09:48:48 2025 +0300 stream_par_optimizations_a2_mapZIOParUnordered: document mapOutZIOPar commit a1261e6 Author: Eyal Farago-Hagag <efaragohagag@zscaler.com> Date: Mon May 26 08:19:15 2025 +0300 stream_par_optimizations_a2: eliminate latches in mapZIOPar commit 48d1872 Author: Eyal Farago-Hagag <efaragohagag@zscaler.com> Date: Mon May 26 07:44:48 2025 +0300 stream_par_optimizations_a2_mapZIOParUnordered: fix mapOutZIOPar commit 9d1ce86 Author: Eyal Farago-Hagag <efaragohagag@zscaler.com> Date: Sun May 25 09:24:20 2025 +0300 stream_par_optimizations_a2: eliminate childScope (par ordered) commit f09e3fb Author: Eyal Farago-Hagag <efaragohagag@zscaler.com> Date: Fri May 2 18:12:44 2025 +0300 stream_par_optimizations_a2: correct version commit 66a09e5 Author: Eyal Farago-Hagag <efaragohagag@zscaler.com> Date: Fri May 2 16:55:50 2025 +0300 stream_par_optimizations_a2: strm.mapZIOPar: safely use forkDaemon
5d4d9fb
to
72383ef
Compare
…Managed, move all mutations into a single ZIO.succeed block
CC @guizmaii , @regiskuckaertz , @kyri-petrou |
@kyri-petrou , any chance to get this reviewed? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This work introduces couple of optimizations to
ZChannel.mapOutZIOPar
that sums up to roughly an X3.5 benchmark improvement.forkScoped
, fibers are forked as daemons and stored in a local array using a cyclic-buffer pattern. This is possible since the number of fibers at any given time is bound bybufferSize + 2
where the extra 2 are the fiber about to be offered to the queue and the last fiber removed from the queue.a. furthermore, fibers are responsible for removing themselves from the array once completed.
b. no race over array 'adds', potential race on read (due to fibers nulling their slot in the array) is not an issue since the reader can identify fibers which are already terminated.
c. this array is used to interrupt pending fibers at end of execution, it's also used to await pending fiber in the 'happy case' completion.
d. fibers are stored in the array before actually started, this guarantees no fibers will be missed once the array is examined (either for interrupting or awaiting all fibers).
a. consumer starts with all available permits, once exhausted it'd acquire all currently available permits from the
semaphore (potentially blocking).
b. acquired permits are transfered to the forked fibers which release them back to the semaphore upon completion, potentially unblocking the forker.
a. in the new implementation the forker acquires a permit from the semaphore and transfers it to the forked fiber, this effectively enforces the ordering between fibers (later tasks can't 'still' a permit from earlier tasks).
b. successful completion is now coordinated by leveraging the array tracking inflight fibers. once upstream completed there will be no more forked fibers and no more insertions into this array so it can be used to obtain a snapshot of still running fibers which are then awaited (notice the snapshot is not accurate and may include already completed fibers, but awaiting these is a no-op).
so numbers!
zioMapParUnordered
is next on my list 😎