Repository navigation
[Core] Elide finished trigger state when no subtrigger can finish - #41719
Anurag-S1ngh wants to merge 1 commit into
Conversation
Cache whether the finished-subtrigger bitset is needed and skip it for triggers that never persist finished bits, including Repeatedly over once-style triggers. Keep the state for AfterEach, OrFinally, late AfterWatermark, and the new-window optimization.
There was a problem hiding this comment.
📋 Review Summary
This PR optimizes TriggerStateMachineRunner by precomputing finishedSetNeeded and eliding FINISHED_BITS_TAG state reads/writes for trigger trees that never persist finished bits across calls (such as Never, ReshuffleTrigger, and Repeatedly wrapping once-style triggers like AfterPane, AfterDelayFromFirstElement, AfterWatermark.FromEndOfWindow, AfterFirst, and AfterAll). It also properly preserves the state when useNewWindowOptimization is enabled or when stateful composite triggers (AfterEach, OrFinally, AfterWatermarkEarlyAndLate) are present.
🔍 General Feedback
- The structural analysis of trigger state machines in
canElideFinishedSet,canElideRepeatedSubtree, andisOnceStyleTriggeris sound: all included subtriggers underRepeatedlyonly set finished bits duringonFireand unconditionally mark the direct child ofRepeatedlyas finished upon firing, whichRepeatedlyStateMachine.onFireimmediately clears viaresetTree()beforepersistFinishedSetis called. - Unit test coverage in
TriggerStateMachineRunnerTestthoroughly exercises both the elided trigger configurations and the cases that still require persisted finished bits.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @shunping added as fallback since no labels match configuration 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). |
Summary
Elide the finished-subtrigger bitset in
TriggerStateMachineRunnerwhen no trigger in the tree can leave a finished bit set. Today onlyDefaultTriggerStateMachinetakes this shortcut. This extends the shortcut toRepeatedly.forever(...)over once-style triggers, plusNeverStateMachineandReshuffleTriggerStateMachine.For these trees the bitset is read on every element and timer, but no bit can survive between calls. Bits set during
onFireare cleared byRepeatedlybefore the state is persisted, andonMergeonly sets a bit when a merging window already had one stored. So the state is always empty and the reads are wasted work.Changes
DefaultTriggerStateMachine,NeverStateMachine,ReshuffleTriggerStateMachine.RepeatedlyStateMachinewhose repeated subtree is once-style:AfterPaneStateMachine,AfterDelayFromFirstElementStateMachine,AfterWatermarkStateMachine.FromEndOfWindow,AfterFirstStateMachineorAfterAllStateMachineof once-style triggers, and nestedRepeatedlyStateMachine.AfterEachStateMachine,OrFinallyStateMachine,AfterWatermarkStateMachinewith late firings, and when the new-window optimization is enabled.Testing
./gradlew :runners:core-java:test --tests "org.apache.beam.runners.core.triggers.*" --tests "org.apache.beam.runners.core.ReduceFnRunnerTest"(142 tests passed)./gradlew :runners:core-java:spotlessCheck :runners:core-java:checkstyleMain :runners:core-java:checkstyleTestFixes #17961.