Repository navigation
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR optimizes hot-path execution in SimpleParDoFn and SimpleParDoFnHelpers by replacing the anonymous WindowedValueMultiReceiver with a static OutputManager featuring identity-based TupleTag caching, precomputing hasState per bundle, and adding a GlobalWindow fast path for state cleanup registration. It also hardens bundle lifecycle state cleanup in abort() and adds comprehensive unit test coverage in SimpleParDoFnHelpersTest.
🔍 General Feedback
- The
OutputManageridentity caching (mainOutputTag,altMainTag, and boundedcachedTags) cleanly handles both directc.output(elem)calls and deserializedstatic final TupleTaginstances without hash map lookups or write-barrier thrashing. - Extracting cold paths (
lazyStartBundle,processWithSideInputs) and avoidingWindowedValue#getWindows()/ iterator allocations onValueInGlobalWindowandTimestampedValueInGlobalWindoware well-targeted JIT/allocation improvements. - State lifecycle management (
hasState,fnSignature, andstartBundlepreconditions) and unit tests are thorough and well-structured.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #41806 +/- ##
=============================================
- Coverage 61.24% 58.88% -2.37%
+ Complexity 16932 2342 -14590
=============================================
Files 2856 1136 -1720
Lines 279320 171087 -108233
Branches 13478 1567 -11911
=============================================
- Hits 171068 100740 -70328
+ Misses 101414 67789 -33625
+ Partials 6838 2558 -4280
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @kennknowles added as fallback since no labels match configuration 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). |
|
Also R: @arunpandianp as you've recently been in this code. |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
| @Nullable Receiver mainReceiver = | ||
| receivers != null && mainReceiverIndex >= 0 && mainReceiverIndex < receivers.length |
There was a problem hiding this comment.
any reason to not move this to OutputManager constructor?
| // checks across concurrent worker threads. | ||
| // | ||
| // TODO: Once Beam is on JDK 24, we can revert to a simpler instanceof call. | ||
| private static final Class<?> VALUE_IN_GLOBAL_WINDOW_CLASS = |
There was a problem hiding this comment.
can we reuse constants in runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/DataflowOutputCounter.java?
There was a problem hiding this comment.
done, though I'm not sure having SimpleParDoFn read the constants out of DataflowOutputCounter is cleaner. Added a comment to cleanup. Also it does seem like this is a workaround to a hotspot bug that will be fully fixed by JDK 24, so we might be able to remove entirely then.
| activeFnInfo = null; | ||
| fnSignature = null; | ||
| hasState = false; | ||
| sideInputProcessor = null; |
There was a problem hiding this comment.
nit: sideInputProcessor = null can be removed.
| if (hasState) { | ||
| // These elements are now processed. Register cleanup timers for all the unblocked | ||
| // windows. | ||
| helpers.registerStateCleanup( |
There was a problem hiding this comment.
this can call the new registerStateCleanup method.
- Outline lazyStartBundle and processWithSideInputs in SimpleParDoFn and skip elem.getWindows() on stateless DoFns. - Cache hasState, isStreaming, and mainReceiverIndex in SimpleParDoFnHelpers and reset fields in finally on abort(). - Replace anonymous outputManager with OutputManager using reference-equality fast paths for mainOutputTag/altMainTag, a bounded per-slot tag cache for multi-output DoFns, and lazy undeclaredOutputs map allocation. - Fast-path GlobalWindow state cleanup timer registration without calling elem.getWindows().
cc26f04 to
a4fa7c2
Compare
Reduces per-element dispatch and allocation overhead in Dataflow worker SimpleParDoFn and SimpleParDoFnHelpers:
SimpleParDoFn: Outlines lazyStartBundle() and processWithSideInputs() to keep processElement()/onProcessWindowedValue() small, and skips elem.getWindows() entirely on stateless DoFns.
SimpleParDoFnHelpers: Caches hasState, isStreaming, and mainReceiverIndex instead of re-deriving them per element, and resets bundle state in finally on abort().
OutputManager: Replaces the anonymous output manager with a dedicated class using reference-equality fast paths for mainOutputTag (and a deserialized altMainTag), a bounded per-slot identity cache (<= 8 outputs), and lazily allocated undeclaredOutputs.
State cleanup: Fast-paths known GlobalWindow WindowedValue implementations in registerStateCleanup() without allocating/iterating elem.getWindows().
Adds unit tests in SimpleParDoFnHelpersTest covering hasState lifecycle/abort cleanup, multi-output/undeclared/null-tag routing across bundles, and state cleanup fast paths.