stream: optimize gather hot path and polish for upstream#2848
Draft
He-Pin wants to merge 1 commit into
Draft
Conversation
pjfanning
requested changes
Apr 7, 2026
| * | ||
| * '''Cancels when''' downstream cancels | ||
| * | ||
| * @since 1.3.0 |
| * The collector is only valid while the current [[Gatherer]] callback is running. | ||
| * Emitted elements MUST NOT be `null`. | ||
| * | ||
| * @since 1.3.0 |
| * A new gatherer instance is created for each materialization and on each supervision restart. | ||
| * It can keep mutable state in fields or via captured variables. | ||
| * | ||
| * @since 1.3.0 |
| * the `onComplete` callback. | ||
| * | ||
| * @param f the one-to-one transformation function | ||
| * @since 1.3.0 |
Member
There was a problem hiding this comment.
all the 1.3.0 in this class or elsewhere in this PR should be 2.0.0
| /** | ||
| * Create a `Source` from an `Optional` value, emitting the value if it is present. | ||
| * | ||
| * @since 1.3.0 |
| * | ||
| * '''Cancels when''' downstream cancels | ||
| * | ||
| * @since 1.3.0 |
Member
There was a problem hiding this comment.
all of these 1.3.0s are wrong - should be 2.0.0
| * '''Cancels when''' downstream cancels | ||
| * | ||
| * @since 1.3.0 | ||
| * @since 2.0.0 |
| * '''Cancels when''' downstream cancels | ||
| * | ||
| * @since 1.3.0 | ||
| * @since 2.0.0 |
Member
There was a problem hiding this comment.
why are all the mapOptions being changed? Change back to 1.3.0
He-Pin
added a commit
that referenced
this pull request
Jun 15, 2026
Motivation: The Paradox doc build fails with "Unknown page [../../actors.md]" because gather.md is three directory levels below the paradox root. Modification: Change ../../actors.md to ../../../actors.md, matching the pattern used in neighboring ask.md. Result: Paradox doc build succeeds. Tests: Not run - docs only (path fix verified by comparing ask.md in same directory) References: Refs #2848
He-Pin
added a commit
to He-Pin/incubator-pekko
that referenced
this pull request
Jun 15, 2026
Motivation: The Paradox doc build fails with "Unknown page [../../actors.md]" because gather.md is three directory levels below the paradox root. Modification: Change ../../actors.md to ../../../actors.md, matching the pattern used in neighboring ask.md. Result: Paradox doc build succeeds. Tests: Not run - docs only (path fix verified by comparing ask.md in same directory) References: Refs apache#2848
93f35dc to
599a39f
Compare
Motivation: The gather operator's hot path had unnecessary overhead and its docs needed refinement for upstream contribution quality. Modification: - Optimize gather hot path: eliminate boolean field, inline callbacks - Add comprehensive test spec (849 lines) and JMH benchmarks - Refine docs, @SInCE markers, and API annotations - Apply scalafmt and javafmt formatting - Address deep review findings Result: Improved gather performance and production-quality test coverage. Tests: - sbt "stream / Test / testOnly *GatherSpec" References: Refs apache#2848
599a39f to
da7b38e
Compare
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
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.
Summary
This PR applies deep code review and optimizations on top of the
gatheroperator implementation. All changes are targeted at making the contribution meet Apache Pekko CONTRIBUTING standards.Hot path optimizations (Ops.scala)
hasCallbackFirstboolean field — usecallbackFirst eq nullas sentinel, saving 2 writes + 1 read per elementpushCallbackSingleintoonPushSingle— remove 1 virtual dispatch per element on the common pathafterPushFinalAction()— so the JIT optimises the hot branch independentlyhadContextparameter frommaybeRunFinalAction/pushPending*— checkneedInvokeOnCompleteCallbackdirectlymultiMode = falseafter overflow is fully drained, so subsequent single-output calls return to the fast pathDocumentation & API polish
@sinceversion: unify to1.3.0across all DSL files (was inconsistently2.0.0)collector.push()instead ofcollector.apply()(idiomatic API)gather.mdto remove internal PR references and add third example (distinctUntilChanged)bufferUntilChangedanddistinctUntilChangedpatternsTest & build fixes
distinctUntilChangedtest: remove deadlastElement = Some(elem)in the duplicate caseKeepandFlowimports inFlowGatherSpecZipWithIndexBenchmark(avoid wildcard import)Test plan
stream/compilesucceedsstream: ...)