Skip to content

In TriggerRunner, avoid reading the set of finished subtriggers when no subtrigger ever finishes. #17961

Todo

Description

@kennknowles

For a trigger expression, TriggerRunner tracks which of the subexpressions have finished to track which subexpression is the currently active trigger that determines when output is permitted. For some triggers (such as the default trigger) this information is not needed. The reads and writes of this data can be elided.

Imported from Jira BEAM-30. Original Jira may contain additional context.
Reported by: kenn.

Activity

  1. Moemenmohamed24 commented on Jul 22, 2026

    @Moemenmohamed24

    Hi ! @kennknowles Is anyone working on this?

  2. kennknowles commented on Jul 23, 2026

    @kennknowles
    MemberAuthor

    No I don't think anyone is working on it. It is a pretty niche issue that has been sitting here for a very very long time. But it probably still applies! It may not make any difference to a real-world pipeline, actually... but I must have filed it for some reason 😅 . Feel free to take a look if you like.

  3. rokadepiyush49-rgb commented on Nov 20, 2026

    @rokadepiyush49-rgb

    Hi @kennknowles, I've cloned the repo and traced this on current master (36fd8ac).

    Problem
    TriggerStateMachineRunner.isFinishedSetNeeded() only skips the FINISHED_BITS state for DefaultTriggerStateMachine (the TODO next to it). Other trees whose bitset is always empty between calls still read that state on every element and every shouldFire.

    What I found while tracing

    • Under Repeatedly.forever(...) with once-style children (AfterPane, AfterProcessingTime, AfterWatermark.pastEndOfWindow(), and AfterFirst/AfterAll of those), a child's bit is set and then cleared by resetTree() in the same onFire. onMerge only sets it if a merging window already had it set, so nothing is ever stored.
    • "The root never finishes" isn't enough on its own:
      • AfterWatermark with late firings never finishes, but the early child's bit records the early → late switch across calls.
      • AfterEach keeps earlier children's bits between firings.
    • Since Use trigger state to know if a window is new and optimize reads #37574, isNew() uses this state to tell whether a window has been seen before when useNewWindowOptimization is on. Skipping it for more triggers would quietly turn that optimisation off for them.
    flowchart TD
      S["isFinishedSetNeeded()"] --> D{"root is DefaultTrigger?"}
      D -- "yes" --> SKIP["skip FINISHED_BITS (as today)"]
      D -- "no" --> W{"useNewWindowOptimization?"}
      W -- "yes" --> NEED["read/write bitset (as today)"]
      W -- "no" --> T{"can any node keep a bit set between calls?"}
      T -- "no: Repeatedly over once-style triggers" --> SKIP
      T -- "yes or unknown: OrFinally, AfterEach, late AfterWatermark" --> NEED
    
    Loading

    Proposed approach

    • Add a conservative recursive check in the runner (no public API change). It returns "not needed" only for the safe shapes above and "needed" for everything else.
    • Keep the current behaviour whenever useNewWindowOptimization is on.
    • In TriggerStateMachineRunnerTest, assert that Repeatedly.forever(AfterPane...) never touches FINISHED_BITS, and that AfterEach, orFinally and early/late AfterWatermark behave as before. Run ReduceFnRunnerTest as a regression check.

    Does that rule match what you had in mind? I saw @Moemenmohamed24 asked about this in July. If they're not working on it, can I take this issue?

  4. Anurag-S1ngh commented on Nov 25, 2026

    @Anurag-S1ngh
    Contributor

    I saw @rokadepiyush49-rgb's earlier interest. There has been no assignment, follow-up, or PR, so I'll take this one.

    .take-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions