The GitHub Actions job "Nightly Builds" on pekko.git/main has succeeded.
Run started by GitHub user He-Pin (triggered by He-Pin).

Head commit for run:
2fe223701f9118117fa2224c3065e8e1293c198e / He-Pin(kerr) <[email protected]>
fix(stream): replace O(n) finalization scan with O(1) counter in 
afterStageHasRun (#3373)

Motivation:
PR #3030 (commit 3fbb1848f3) introduced releaseStage() which nulls out
connection references during stage finalization. The afterStageHasRun
method was changed to scan all initializedStages on every event dispatch
to find completed stages. With 1M+ stages (InterpreterStressSpec), this
causes O(n^2) behavior — the test thread hangs indefinitely at
GraphInterpreter.afterStageHasRun (issue #3372).

Modification:
Replace the pendingFinalization Boolean with a pendingFinalizations Int
counter. The O(1) fast path finalizes the active stage directly and
decrements the counter by 1. The O(n) scan loop only runs when the
counter is still > 0 (cascading completion where multiple stages
completed during one event dispatch). A Boolean cannot distinguish
"one stage pending" from "multiple stages pending" — the fast path
would erase signals for other stages, breaking cascading finalization.

Result:
afterStageHasRun is O(1) in the common case (long chains where each
event completes exactly one stage). The O(n) scan only runs for
cascading completions (rare in practice). InterpreterStressSpec with
1M stages completes in bounded time instead of hanging.

Tests:
- sbt "stream-tests / Test / testOnly 
org.apache.pekko.stream.impl.fusing.GraphInterpreterSpec" — 14/14 passed
- sbt "stream-tests / Test / testOnly 
org.apache.pekko.stream.impl.fusing.GraphInterpreterPortsSpec 
org.apache.pekko.stream.impl.fusing.LifecycleInterpreterSpec" — 75/75 passed
- sbt "stream / scalafmt" — no formatting changes needed

References:
Fixes #3372

Report URL: https://github.com/apache/pekko/actions/runs/29916485832

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to