Skip to content

Cubic pacing rate tolerates a zero smoothed RTT - #109

Open
rnro wants to merge 3 commits into
apple:mainfrom
rnro:quic-cubic-pacing-divide-by-zero
Open

Cubic pacing rate tolerates a zero smoothed RTT#109
rnro wants to merge 3 commits into
apple:mainfrom
rnro:quic-cubic-pacing-divide-by-zero

Conversation

@rnro

@rnro rnro commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Cubic.updatePacerState divides by the smoothed RTT in microseconds, so a small smoothed RTT is rounded to zero and traps.

Prague.updatePacerState already uses its initial estimate in the case of a zero smoothed RTT, so this change mirrors that approach.

`Cubic.updatePacerState` divides by the smoothed RTT in microseconds, so a smoothed
RTT of zero traps. `Prague.updatePacerState` already uses its initial estimate
in the case of a zero smoothed RTT, so this change mirrors that approach.
@rnro rnro added the 🔨 semver/patch No public API change. label Aug 21, 2026
@rnro rnro changed the title Cubic pacing rate tolearates a zero smoothed RTT Cubic pacing rate tolerates a zero smoothed RTT Aug 21, 2026
Comment thread Sources/SwiftNetwork/QUIC/Prague.swift Outdated
@@ -312,7 +315,7 @@ struct Prague: CongestionControlProtocol, CubicLikeProtocol {
}

// Multiply by USEC_PER_SEC as sRTT is in microseconds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Multiply by USEC_PER_SEC as sRTT is in microseconds
// Multiply by USEC_PER_SEC as smoothedRTTInMicroseconds is in microseconds

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if congestionWindow < slowStartThreshold {
rate *= 2
}
// Multiply by USEC_PER_SEC as srtt is in microseconds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I've taken a slightly different approach here. I think the underlying issue once I called it smoothedRTTInMicroseconds is that the units of rate were not clear. I've changed that and I think then the comment is not needed because the code is self-evident.

Comment thread Sources/SwiftNetwork/QUIC/Cubic.swift Outdated
return
}

// Zero microseconds means either that no measurement has landed yet or that one rounded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can this happen when we are called after ackEnd? At that time I expect we should have an RTT estimate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I don't think the "no measurement has landed yet" part can happen. I've updated the comment.

@rnro
rnro requested a review from rpaulo August 25, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants