Repository navigation
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR optimizes element emission hot paths in DoFnOutputReceivers and OutputBuilderSuppliers by introducing direct build methods (build, buildWithTimestamp, buildWindowedValue) on OutputBuilderSupplier and bypassing intermediate WindowedValues.Builder, WindowedValue<Row>, and receiver lambda allocations. It also caches SchemaCoder.getFromRowFunction() in RowOutputReceiver, removes redundant builder wrapping, and includes comprehensive unit tests and JMH benchmarks.
🔍 General Feedback
- The fast-path implementations in
ElementOutputBuilderSupplier,WindowedContextOutputReceiver, andRowOutputReceivercleanly preserve all element metadata (timestamp,windows,PaneInfo,recordId,recordOffset,CausedByDrain,ValueKind, and active OpenTelemetryContextwithContext.root()normalization) while maintaining@FunctionalInterfacecompatibility onOutputBuilderSupplier. - Test coverage in
DoFnOutputReceiversTestandOutputBuilderSuppliersTestthoroughly exercises allWindowedValueshapes, tagged/untagged receivers, row receivers, and edge cases such as nestedWindowedValuepayloads andnullelements.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
Assigning reviewers: R: @ahmedabu98 for label java. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## perf/windowed-values #41814 +/- ##
=======================================================
Coverage 59.59% 59.59%
Complexity 5157 5157
=======================================================
Files 1470 1470
Lines 187850 187850
Branches 3828 3828
=======================================================
Hits 111942 111942
Misses 72503 72503
Partials 3405 3405 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…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.
3db35d1 to
450947c
Compare
Stacked on #41813 (
perf/windowed-values).Avoids intermediate
WindowedValues.Builderand lambda allocations when emitting elements throughDoFnOutputReceiversandOutputBuilderSuppliers:OutputBuilderSupplier/OutputBuilderSuppliers: Adds defaultbuild,buildWithTimestamp, andbuildWindowedValuemethods and implements them inElementOutputBuilderSupplierby delegating directly toWindowedValues.ofWithCurrentContext(...)andWindowedValues.builder(template, value).DoFnOutputReceivers: Implements directoutput,outputWithTimestamp, andoutputWindowedValuemethods onWindowedContextOutputReceiverandRowOutputReceiver, cachesfromRowFunctiononRowOutputReceiver, and removes redundantWindowedValues.builder(...)wrapping inbuilder().SplittableParDoandSplittableParDoNaiveBoundedto useWindowedValues.builder(template, value).DoFnOutputReceiversTestandOutputBuilderSuppliersTest, plus JMH microbenchmarks (OutputReceiverBenchmarkandOutputReceiverBenchmarkTest) covering both output receivers andFullWindowedValueCoder.Performance Results
Measured via forked A/B JMH on JDK 21 (
OutputReceiverBenchmark,Mode.AverageTime,-f 1 -wi 2 -i 3 -w 500ms -r 500ms -prof gc), comparing stack base #41813 (perf/windowed-values@718a3fe2ba8) vs. #41814 (perf/dofn-output-receivers@3db35d11a55) — both runs share identicalWindowedValues/WindowedValue/IterableLikeCoderclasses from #41813, isolating onlyDoFnOutputReceivers,OutputBuilderSupplier, andOutputBuilderSuppliers(lowerns/opis better):templateKindns/op)ns/op)B/op)B/op)windowedReceiverOutputTaggedGLOBAL_MINwindowedReceiverOutputTaggedSINGLE_INTERVALwindowedReceiverOutputTaggedMULTI_INTERVALwindowedReceiverOutputUntaggedGLOBAL_MINwindowedReceiverOutputUntaggedSINGLE_INTERVALwindowedReceiverOutputUntaggedMULTI_INTERVALwindowedReceiverOutputViaBuilderGLOBAL_MINwindowedReceiverOutputViaBuilderSINGLE_INTERVALwindowedReceiverOutputViaBuilderMULTI_INTERVALwindowedReceiverOutputWithTimestampGLOBAL_MINwindowedReceiverOutputWithTimestampSINGLE_INTERVALwindowedReceiverOutputWithTimestampMULTI_INTERVALwindowedReceiverOutputWindowedValueGLOBAL_MINwindowedReceiverOutputWindowedValueSINGLE_INTERVALwindowedReceiverOutputWindowedValueMULTI_INTERVALwindowedReceiverPerElementConstructionGLOBAL_MINwindowedReceiverPerElementConstructionSINGLE_INTERVALwindowedReceiverPerElementConstructionMULTI_INTERVALrowReceiverOutputGLOBAL_MINrowReceiverOutputSINGLE_INTERVALrowReceiverOutputMULTI_INTERVALrowReceiverOutputWithTimestampGLOBAL_MINrowReceiverOutputWithTimestampSINGLE_INTERVALrowReceiverOutputWithTimestampMULTI_INTERVALrowReceiverOutputViaBuilderGLOBAL_MINrowReceiverOutputViaBuilderSINGLE_INTERVALrowReceiverOutputViaBuilderMULTI_INTERVALKey Takeaways
WindowedContextOutputReceiverpaths (3.0×–5.2×faster,-168 B/op/-77.8%to-80.8%allocation): Eliminating intermediateWindowedValues.Builderand capturing-lambda allocations drops every output call from ~31–38 ns (208–216 B/op) to ~6–11 ns (40–48 B/op, leaving only the emittedWindowedValueitself).builder().output()path (3.1×–3.5×faster,-168 B/op): Removing the redundantWindowedValues.builder(...)wrapper bringswindowedReceiverOutputViaBuilderdown to the same40–48 B/opfloor.3.2×–6.1×faster,-168to-208 B/op): With the builder/lambda chain removed, C2 even scalar-replaces the transient receiver and supplier onGLOBAL_MIN(248 → 40 B/op,6.12×faster).RowOutputReceiver(2.3×–3.7×faster,-136 B/opon direct paths;1.5×–1.7×faster,-64 B/opon builder path): Directoutput/outputWithTimestampplus cachingfromRowFunctionremoves136 B/op(-73.9%to-77.3%).