Skip to content

optimize: remove unnecessary DelayCancellation stage from RestartFlow#2975

Open
He-Pin wants to merge 1 commit into
mainfrom
optimize-restartflow-delay-cancellation
Open

optimize: remove unnecessary DelayCancellation stage from RestartFlow#2975
He-Pin wants to merge 1 commit into
mainfrom
optimize-restartflow-delay-cancellation

Conversation

@He-Pin
Copy link
Copy Markdown
Member

@He-Pin He-Pin commented May 16, 2026

Motivation

RestartFlow had ~3x less throughput than RetryFlow due to an unnecessary DelayCancellation stage in the inner flow graph. This stage added per-element overhead (extra grab/push/pull operations) even when not needed.

See: akka/akka-core#31225

Modification

Only apply the DelayCancellation stage when onlyOnFailures mode is enabled. For the common RestartFlow.withBackoff case, the stage is removed, eliminating the per-element overhead.

The DelayCancellation stage was a workaround for a race condition (see #23909) where cancellation could arrive before a failure signal in onlyOnFailures mode. For the non-onlyOnFailures case, the SubSourceOutlet.onDownstreamFinish handler already schedules a restart, so the delay is unnecessary.

Result

Significantly improved throughput for RestartFlow.withBackoff. The onFailuresWithBackoff path retains the DelayCancellation stage for correctness.

Tests

  • All 38 existing RestartSpec tests pass

Refs

Refs akka/akka-core#31225

Motivation:
RestartFlow had ~3x less throughput than RetryFlow due to an unnecessary
DelayCancellation stage in the inner flow graph. This stage added per-element
overhead (extra grab/push/pull operations) even when not needed.

Modification:
Only apply the DelayCancellation stage when onlyOnFailures mode is enabled.
For the common RestartFlow.withBackoff case, the stage is removed.

Result:
Significantly improved throughput for RestartFlow.withBackoff. The
onFailuresWithBackoff path retains the DelayCancellation stage for
correctness (race condition fix for #23909).

Tests:
- All 38 existing RestartSpec tests pass

Refs: akka/akka-core#31225
@pjfanning pjfanning added this to the 2.0.0-M3 milestone May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants