Repository navigation
Conversation
… helpers - WindowedValues: add singleWindowOrNull, builder(template, value), and ofWithCurrentContext(...) overloads; track singleWindow in Builder without allocating wrapper collections; normalize OpenTelemetry Context.root() to null; mark concrete subclasses final and optimize of()/withValue()/explodeWindows(). - IterableLikeCoder & FullWindowedValueCoder: add @internal single-element and size-header helpers to avoid singleton-list allocations on single-window encode/decode/registerByteSizeObserver, reuse cached windowsCoder on multi-window decode, and check plain paneInfo metadata bit before volatile load. - Add unit tests in WindowedValueTest and CollectionCoderTest.
…uild paths - OutputBuilderSupplier / OutputBuilderSuppliers: add direct build, buildWithTimestamp, and buildWindowedValue methods backed by WindowedValues.ofWithCurrentContext to avoid intermediate Builder allocations. - DoFnOutputReceivers: implement direct output/outputWithTimestamp/ outputWindowedValue on WindowedContextOutputReceiver and RowOutputReceiver, cache fromRowFunction, and drop redundant Builder copying. - Update SplittableParDo and SplittableParDoNaiveBounded to use WindowedValues.builder(template, value). - Add unit tests in DoFnOutputReceiversTest and OutputBuilderSuppliersTest, and JMH benchmarks in OutputReceiverBenchmark.
Contributor
There was a problem hiding this comment.
📋 Review Summary
This PR introduces several well-targeted Java SDK hot-path optimizations, including direct WindowedValue construction via OutputBuilderSupplier.build(...), cached OutputReceiver and MultiOutputReceiver instances in SimpleDoFnRunner and FnApiDoFnRunner, a dedicated two-window DualWindowedValue representation, and direct byte-size accumulation in FullWindowedValueCoder and IterableLikeCoder. The changes are thoroughly benchmarked and well-covered by unit tests.
🔍 General Feedback
- The new
OutputBuilderSupplier.builddefault method and fast-path implementations cleanly bypass intermediateAutoValue_WindowedValues_Builderallocations while preserving context metadata (recordId,recordOffset,causedByDrain,openTelemetryContext). - One compatibility issue was identified where
SimpleDoFnRunner.outputWindowedValuenow passesnulltoWindowedValueMultiReceiver.output(TupleTag, WindowedValue)when emitting to the main output; several existing runner implementations (such as DirectRunner, Spark, and Flink) assume a non-nullTupleTagand use it as a map key or check it withcheckArgumentNotNull.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
💬 Inline Findings
runners/core-java/src/main/java/org/apache/beam/runners/core/SimpleDoFnRunner.java(line 313): 🔴 Critical:outputWindowedValue(WindowedValue<OutputT>)delegates tooutputWindowedValue((TupleTag<OutputT>) null, windowedElem), which now passes anullTupleTagdirectly tooutputManager.output(outputTag, windowedElem). Previously,outputWindowedValue(WindowedValue<OutputT>)passedmainOutputTag(outputManager.output(mainOutputTag, windowedElem)). SeveralWindowedValueMultiReceiverimplementations across runners require a non-null tag (e.g.,ParDoEvaluator.BundleOutputManagerindirect-javacallscheckArgumentNotNull(bundles.get(tag), ...), and Spark/Samza/Jet runners index into maps or compare againstmainOutputTag), which will causeNullPointerExceptionorIllegalArgumentExceptionon main outputs. ResolvenulltomainOutputTagbefore callingoutputManager.output(...).
outputManager.output(outputTag == null ? (TupleTag<T>) mainOutputTag : outputTag, windowedElem);
Contributor
Author
|
Superseded by stacked PR #41814 (recreated from an apache/beam branch to use GitHub native stacked PRs). |
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.
Depends on the WindowedValues fast-paths PR (pr/41803) - for now contains all those changes.
Avoids intermediate WindowedValues.Builder and lambda allocations when emitting elements through DoFnOutputReceivers and OutputBuilderSuppliers:
OutputBuilderSupplier / OutputBuilderSuppliers: Adds default build, buildWithTimestamp, and buildWindowedValue methods and implements them in ElementOutputBuilderSupplier by delegating directly to WindowedValues.ofWithCurrentContext(...) and WindowedValues.builder(template, value).
DoFnOutputReceivers: Implements direct output, outputWithTimestamp, and outputWindowedValue methods on WindowedContextOutputReceiver and RowOutputReceiver, caches fromRowFunction on RowOutputReceiver, and removes redundant WindowedValues.builder(...) wrapping in builder().
Updates SplittableParDo and SplittableParDoNaiveBounded to use WindowedValues.builder(template, value).
Adds unit tests in DoFnOutputReceiversTest and OutputBuilderSuppliersTest, plus JMH microbenchmarks (OutputReceiverBenchmark and OutputReceiverBenchmarkTest) covering both output receivers and FullWindowedValueCoder.