Skip to content

fix: count a sent packet before judging the sender app-limited - #3963

Merged
larseggert merged 1 commit into
mozilla:mainfrom
larseggert:fix/cc-app-limited-accounting
Sep 10, 2026
Merged

larseggert merged 1 commit into
mozilla:mainfrom
larseggert:fix/cc-app-limited-accounting

Conversation

@larseggert

Copy link
Copy Markdown
Collaborator

A batch can exceed cwnd, leaving the pipe empty when it is sent. Judging app_limited() there suspends congestion window growth for the life of the connection.

Copilot AI balanced review requested due to automatic review settings September 10, 2026 06:36

Copilot AI left a comment

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.

🟢 Approval recommended

The accounting order is corrected and the affected boundary conditions are adequately tested.

Pull request overview

Corrects app-limited detection by accounting for a sent packet before evaluating congestion-window utilization.

Changes:

  • Reorders bytes-in-flight accounting.
  • Updates app-limited thresholds and adds a regression test.
File summaries
File Description
neqo-transport/src/cc/classic_cc.rs Fixes congestion-window growth classification and tests boundary behavior.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.75%. Comparing base (57ac6ca) to head (e1703fb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3963      +/-   ##
==========================================
- Coverage   96.91%   96.75%   -0.17%     
==========================================
  Files         113      118       +5     
  Lines       39533    39862     +329     
  Branches    39533    39862     +329     
==========================================
+ Hits        38315    38567     +252     
- Misses       1203     1270      +67     
- Partials       15       25      +10     
Flag Coverage Δ
freebsd 94.07% <100.00%> (-0.16%) ⬇️
linux 96.94% <100.00%> (-0.01%) ⬇️
macos 95.02% <100.00%> (-0.01%) ⬇️
windows 95.08% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
neqo-common 99.26% <ø> (ø)
neqo-http3 95.28% <ø> (ø)
neqo-qpack 96.88% <ø> (ø)
neqo-transport 97.68% <100.00%> (-0.02%) ⬇️
neqo-udp 95.37% <ø> (ø)
mtu 89.13% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot left a comment

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.

Moving bytes_in_flight += pkt.len() above the app_limited() check looks correct to me: it makes the code match the comment right below it ("all in-flight packets up to this one are NOT app-limited") and it fixes the case where first_app_limited stays None, which makes on_packets_acked treat every ack as app-limited and permanently suppress window growth.

I checked the adjusted test constants against the two branches of app_limited() and they're right:

  • slow start: app-limited iff n * MSS < cwnd / 2 ⟹ largest app-limited burst is CWND_INITIAL_PKTS / 2 - 1;
  • congestion avoidance: app-limited iff n * MSS + PACING_BURST_SIZE * MSS < cwnd ⟹ CWND_PKTS_CA - PACING_BURST_SIZE - 1.

Both derivations assume cwnd_initial() is an exact multiple of the PLPMTU. That holds today (1252 B PLPMTU at the test MTU ⟹ 12520 B), but it silently stops holding if the 14_720 clamp in cwnd_initial() ever applies (PLPMTU ≥ 1472). Deriving the constants from cc.cwnd() / cc.max_datagram_size() would make these tests self-maintaining.

Architecturally, the net effect is that the non-app-limited threshold moves down by exactly one packet, so a sender that sends precisely cwnd / 2 (slow start) or cwnd - PACING_BURST_SIZE * MSS (CA) is now credited with fully utilizing the window even though it genuinely had nothing more to send. That's a heuristic either way and RFC 9002 §7.8 leaves the determination implementation-specific, so this isn't a regression — but the authoritative signal ("no more data to send while cwnd_avail() > 0") lives at the process_output layer, not in bytes_in_flight. If this heuristic keeps producing bugs, plumbing that signal down would remove the guesswork entirely.

Minor: the PR description frames this as "a batch can exceed cwnd", but on_packet_sent runs per packet, so packets earlier in a batch are already accounted for — the fix is really an off-by-one on the packet being sent. Worth rewording the commit message since it lands in the history.

Also, CI had not reported any results at review time, so I could not confirm the full suite passes with the new boundaries (sender.rs and connection/tests/cc.rs app-limited expectations look unaffected by inspection).

Comment thread neqo-transport/src/cc/classic_cc.rs Resolved
Comment thread neqo-transport/src/cc/classic_cc.rs Resolved
@codspeed

codspeed Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 3.89%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 80 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation coalesce_acked_from_zero 1 ranges 2.7 µs 2.8 µs -3.89%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing larseggert:fix/cc-app-limited-accounting (e1703fb) with main (154244d)

Open in CodSpeed

@martinthomson martinthomson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am still unclear on why our app-limited check is the way it is. It makes little sense to me. But this is an obvious improvement.

Comment thread neqo-transport/src/cc/classic_cc.rs Resolved

@github-actions github-actions Bot left a comment

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.

The reordering is correct: app_limited() should see the in-flight state after the send, which is what first_app_limited = Some(pkt.pn() + 1) already assumes, and it matches RFC 9002 §7.8 ("unable to fill the congestion window"). Without it, a send that consumes the whole window is judged app-limited, first_app_limited stays None, and on_packets_acked() takes the on_app_limited() path forever — so the "life of the connection" claim in the description holds.

Two architectural notes:

  • The effect is broader than the description suggests: because on_packet_sent() is per-packet, the change shifts the non-app-limited boundary one packet earlier for every burst (bif_before >= T becomes bif_after >= T), which is exactly why both existing tests' expected counts drop by one (5/6 → 4/5 in slow start, 3/4 → 2/3 in CA with the default fixture). Worth saying so in the commit message, since it also means a sender putting exactly cwnd / 2 in flight during slow start is now congestion-limited rather than app-limited. The sender.rs app_limited_suppresses_cwnd_growth_* tests send PACING_BURST_SIZE + 1 packets against a 10-packet initial window, so they are unaffected.
  • Re #discussion_r3977261356: the byte-budget framing is fair — app_limited() only sees bytes. Then the name/doc are the misleading part, since what is being pinned is bytes_in_flight == cwnd, not "one packet". Something like not_app_limited_when_cwnd_fully_consumed would match the property. (My earlier note on sent::make_packet is addressed.)

Minor: several sent::Packet::new() call sites remain in this test module (ecn_ce, no_reaction_to_non_ack_eliciting, …) and could use sent::make_packet for consistency — not this PR's job, but it would finish the cleanup.

Comment thread neqo-transport/src/cc/classic_cc.rs Resolved
Comment thread neqo-transport/src/cc/classic_cc.rs Resolved
Comment thread neqo-transport/src/cc/classic_cc.rs Resolved
A batch can exceed `cwnd`, leaving the pipe empty when it is sent. Judging
`app_limited()` there suspends congestion window growth for the life of the
connection.
@larseggert
larseggert force-pushed the fix/cc-app-limited-accounting branch from 0dd96c9 to e1703fb Compare September 10, 2026 09:06
@github-actions

Copy link
Copy Markdown
Contributor

Performance profiles for profiler.firefox.com

Benchmarks (14)
  • neqo-bin-main: pr · base
  • neqo-common-decoder: pr · base
  • neqo-http3-streams_simulated: pr · base
  • neqo-http3-streams_walltime: pr · base
  • neqo-transport-frame_decode: pr · base
  • neqo-transport-min_bandwidth: pr · base
  • neqo-transport-pacer: pr · base
  • neqo-transport-packet_codec: pr · base
  • neqo-transport-range_tracker: pr · base
  • neqo-transport-rx_stream_orderer: pr · base
  • neqo-transport-send_streams: pr · base
  • neqo-transport-sent_packets: pr · base
  • neqo-transport-transfer_simulated: pr · base
  • neqo-transport-transfer_walltime: pr · base
Comparisons (5)

@github-actions github-actions Bot left a comment

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.

Ordering fix looks right: counting the packet before evaluating app_limited() makes the predicate answer "is the window utilized now that this packet is out", which is what the following block's comment ("all in-flight packets up to this one are NOT app-limited") already assumed. Consistent with RFC 9002 §7.8.

Verified the retuned constants are exact rather than approximate, which is worth noting since the comments only say "one short":

  • Slow start: cwnd_initial == CWND_INITIAL_PKTS * MSS (the 14_720 clamp does not bite for the test PLPMTU), so cwnd / 2 == 5 * MSS and CWND_INITIAL_PKTS / 2 - 1 == 4 is the largest burst with bif < cwnd / 2.
  • CA: after halving, cwnd == 5 * MSS, so bif < cwnd - PACING_BURST_SIZE * MSS == 3 * MSS, and CWND_PKTS_CA - PACING_BURST_SIZE - 1 == 2.

Both also confirm the tests are real regression pins: on main, ABOVE_APP_LIMIT_PKTS was one larger, so the old ordering happened to cross the threshold and the tests passed; with the new values they would fail without the fix.

Resolved from earlier rounds: sent::make_packet is now used throughout, the // A batch exceeding cwnd… comment was reworded per @martinthomson's #discussion_r3976440219, the max_app_limited_pkts helper (and its div_ceil underflow) is gone, and cwnd growth is now asserted exactly as 2 * cwnd.

Two remaining PR-wide observations, neither blocking:

  1. Replacing the derived helper with literal constants was the right call for a regression pin, but it does mean both constants silently encode "the 14_720 clamp is inactive at the test PLPMTU". If cc::tests::MTU ever yields a PLPMTU > 1472 the boundary shifts; the new app_limited() assertions turn that into a loud failure rather than a silent one, so this is fine as-is — just worth a one-line comment on CWND_INITIAL_PKTS / 2 - 1.
  2. On @larseggert's reply about the cwnd-sized packet: agreed that app_limited() is a byte-budget comparison and the test is not redundant with ABOVE_APP_LIMIT_PKTS. It's still the only place exercising bytes_in_flight >= congestion_window, so if the unrealistic packet size bothers reviewers, a while cc.bytes_in_flight() < cc.cwnd() loop of MSS-sized packets (as in cc/tests/cubic.rs::fill_cwnd) reaches the same state with a production-reachable shape.

Comment thread neqo-transport/src/cc/classic_cc.rs Resolved
Comment thread neqo-transport/src/cc/classic_cc.rs Resolved
@larseggert
larseggert added this pull request to the merge queue Sep 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Client/server transfer results

Performance differences relative to 154244d.

No significant performance differences.

Table above only shows statistically significant changes. See all results below.

All results

Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.

Client vs. server Mean±σ Min–Max Median±MAD MiB/s±σ ΔMedian
google-google 461.1 ± 2.7 455.7 – 475.3 460.8 ± 1.6 69.4 ± 0.4
google-neqo-cubic 270.7 ± 1.6 266.1 – 276.1 270.6 ± 1.7 118.2 ± 0.7 -0.4 (-0.1%)
neqo-google-cubic 762.6 ± 3.3 755.7 – 777.6 762.3 ± 1.9 42.0 ± 0.2 -0.6 (-0.1%)
neqo-neqo-cubic 76.8 ± 2.6 71.5 – 88.3 76.8 ± 2.1 416.6 ± 14.0 +0.2 (+0.2%)
neqo-neqo-cubic-nopacing 77.5 ± 4.1 70.9 – 98.2 76.7 ± 2.5 412.8 ± 21.9 +0.1 (+0.2%)
neqo-neqo-newreno 77.1 ± 3.4 72.1 – 96.6 76.8 ± 2.3 414.8 ± 18.0 +0.8 (+1.1%)
neqo-neqo-newreno-nopacing ⚠️ 78.5 ± 3.8 71.6 – 96.6 77.5 ± 1.9 407.7 ± 20.0 +0.2 (+0.2%)
neqo-quiche-cubic 193.2 ± 2.4 188.9 – 209.2 192.9 ± 1.8 165.6 ± 2.1 +0.3 (+0.1%)
neqo-s2n-cubic 216.7 ± 2.0 211.4 – 225.9 216.6 ± 1.6 147.7 ± 1.4 +0.3 (+0.2%)
quiche-neqo-cubic 136.7 ± 2.1 131.4 – 145.7 136.5 ± 1.6 234.2 ± 3.6 -0.1 (-0.1%)
quiche-quiche 135.5 ± 3.6 129.8 – 154.1 135.1 ± 2.7 236.1 ± 6.3
s2n-neqo-cubic 219.4 ± 2.4 215.1 – 228.0 218.9 ± 2.2 145.8 ± 1.6 -1.1 (-0.5%)
s2n-s2n ⚠️ 296.7 ± 30.7 277.9 – 385.6 285.9 ± 3.5 107.9 ± 11.2

Download data for profiler.firefox.com or download performance comparison data.

@github-actions

Copy link
Copy Markdown
Contributor

Failed Interop Tests

QUIC Interop Runner, client vs. server, differences relative to main at 154244d.

neqo-pr as clientneqo-pr as server
neqo-pr vs. go-x-net: BP BA
neqo-pr vs. haproxy: BP BA
neqo-pr vs. linuxquic: ⚠️L1
neqo-pr vs. lsquic: L1 C1
neqo-pr vs. msquic: A L1 C1
neqo-pr vs. mvfst: A ⚠️BA
neqo-pr vs. neqo: A
neqo-pr vs. nginx: BP BA
neqo-pr vs. ngtcp2: CM
neqo-pr vs. picoquic: A
neqo-pr vs. quic-go: A
neqo-pr vs. quic-zig: B
neqo-pr vs. quiche: BP BA
neqo-pr vs. s2n-quic: CM
neqo-pr vs. tquic: S BP BA
neqo-pr vs. xquic: S R Z A L1 C1
aioquic vs. neqo-pr: 🚀L1 CM
go-x-net vs. neqo-pr: CM
kwik vs. neqo-pr: BP BA CM
msquic vs. neqo-pr: CM
mvfst vs. neqo-pr: Z L1 C1 CM
neqo vs. neqo-pr: A
openssl vs. neqo-pr: LR M A CM
quic-go vs. neqo-pr: CM
quiche vs. neqo-pr: baseline result missing
quinn vs. neqo-pr: V2 CM
s2n-quic vs. neqo-pr: run cancelled after 20 min
tquic vs. neqo-pr: CM
xquic vs. neqo-pr: M CM
All results

Succeeded Interop Tests

QUIC Interop Runner, client vs. server

neqo-pr as client

neqo-pr as server

Unsupported Interop Tests

QUIC Interop Runner, client vs. server

neqo-pr as client

neqo-pr as server

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

No significant performance differences relative to 154244d.

All results
transfer/1-conn/1-100mb-resp (aka. Download)/mtu-1504: Change within noise threshold.
       time:   [157.87 ms 158.14 ms 158.41 ms]
       thrpt:  [631.28 MiB/s 632.36 MiB/s 633.43 MiB/s]
change:
       time:   [-0.9230% -0.6797% -0.4328%] (p = 0.00 < 0.05)
       thrpt:  [+0.4347% +0.6843% +0.9316%]
       Change within noise threshold.
transfer/1-conn/10_000-parallel-1b-resp (aka. RPS)/mtu-1504: Change within noise threshold.
       time:   [221.78 ms 222.05 ms 222.31 ms]
       thrpt:  [44.982 Kelem/s 45.035 Kelem/s 45.090 Kelem/s]
change:
       time:   [+0.3323% +0.5299% +0.7134%] (p = 0.00 < 0.05)
       thrpt:  [-0.7084% -0.5271% -0.3312%]
       Change within noise threshold.
transfer/1-conn/1-1b-resp (aka. HPS)/mtu-1504: Change within noise threshold.
       time:   [35.886 ms 35.973 ms 36.065 ms]
       thrpt:  [27.728   B/s 27.799   B/s 27.866   B/s]
change:
       time:   [-0.7996% -0.4370% -0.0286%] (p = 0.02 < 0.05)
       thrpt:  [+0.0286% +0.4390% +0.8060%]
       Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
5 (5.00%) high mild
transfer/1-conn/1-100mb-req (aka. Upload)/mtu-1504: Change within noise threshold.
       time:   [161.17 ms 161.45 ms 161.75 ms]
       thrpt:  [618.24 MiB/s 619.37 MiB/s 620.45 MiB/s]
change:
       time:   [+0.7567% +1.0048% +1.2313%] (p = 0.00 < 0.05)
       thrpt:  [-1.2163% -0.9948% -0.7510%]
       Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
1 (1.00%) low mild
3 (3.00%) high mild
1 (1.00%) high severe
streams/walltime/1-streams/each-1000-bytes: No change in performance detected.
       time:   [548.77 µs 550.91 µs 553.34 µs]
       thrpt:  [1.7235 MiB/s 1.7311 MiB/s 1.7378 MiB/s]
change:
       time:   [-0.3852% +0.1773% +0.7560%] (p = 0.55 > 0.05)
       thrpt:  [-0.7504% -0.1770% +0.3867%]
       No change in performance detected.
Found 13 outliers among 100 measurements (13.00%)
13 (13.00%) high severe
streams/walltime/1000-streams/each-1-bytes: Change within noise threshold.
       time:   [10.500 ms 10.514 ms 10.527 ms]
       thrpt:  [92.765 KiB/s 92.886 KiB/s 93.004 KiB/s]
change:
       time:   [-0.4721% -0.2840% -0.0999%] (p = 0.00 < 0.05)
       thrpt:  [+0.1000% +0.2848% +0.4743%]
       Change within noise threshold.
streams/walltime/1000-streams/each-1000-bytes: Change within noise threshold.
       time:   [30.325 ms 30.362 ms 30.398 ms]
       thrpt:  [31.373 MiB/s 31.410 MiB/s 31.448 MiB/s]
change:
       time:   [-1.1193% -0.9605% -0.7910%] (p = 0.00 < 0.05)
       thrpt:  [+0.7973% +0.9698% +1.1319%]
       Change within noise threshold.
streams-flow-controlled/walltime/1-streams/each-4194304-bytes: Change within noise threshold.
       time:   [25.420 ms 25.453 ms 25.487 ms]
       thrpt:  [156.94 MiB/s 157.15 MiB/s 157.36 MiB/s]
change:
       time:   [-1.1185% -0.9239% -0.7333%] (p = 0.00 < 0.05)
       thrpt:  [+0.7388% +0.9325% +1.1312%]
       Change within noise threshold.
streams-flow-controlled/walltime/10-streams/each-1048576-bytes: Change within noise threshold.
       time:   [69.381 ms 69.454 ms 69.527 ms]
       thrpt:  [143.83 MiB/s 143.98 MiB/s 144.13 MiB/s]
change:
       time:   [-1.8161% -1.6746% -1.5287%] (p = 0.00 < 0.05)
       thrpt:  [+1.5524% +1.7031% +1.8497%]
       Change within noise threshold.
transfer/walltime/pacing-false/varying-seeds: Change within noise threshold.
       time:   [16.859 ms 16.869 ms 16.879 ms]
       thrpt:  [236.98 MiB/s 237.12 MiB/s 237.26 MiB/s]
change:
       time:   [-0.2200% -0.1320% -0.0400%] (p = 0.01 < 0.05)
       thrpt:  [+0.0400% +0.1321% +0.2205%]
       Change within noise threshold.
transfer/walltime/pacing-true/varying-seeds: Change within noise threshold.
       time:   [17.459 ms 17.471 ms 17.484 ms]
       thrpt:  [228.79 MiB/s 228.95 MiB/s 229.11 MiB/s]
change:
       time:   [+1.7837% +1.8876% +1.9926%] (p = 0.00 < 0.05)
       thrpt:  [-1.9537% -1.8526% -1.7524%]
       Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) low mild
transfer/walltime/pacing-false/same-seed: Change within noise threshold.
       time:   [17.006 ms 17.016 ms 17.026 ms]
       thrpt:  [234.93 MiB/s 235.07 MiB/s 235.21 MiB/s]
change:
       time:   [+0.7390% +0.8324% +0.9244%] (p = 0.00 < 0.05)
       thrpt:  [-0.9159% -0.8255% -0.7336%]
       Change within noise threshold.
transfer/walltime/pacing-true/same-seed: Change within noise threshold.
       time:   [17.319 ms 17.335 ms 17.351 ms]
       thrpt:  [230.53 MiB/s 230.75 MiB/s 230.96 MiB/s]
change:
       time:   [-1.0710% -0.9574% -0.8438%] (p = 0.00 < 0.05)
       thrpt:  [+0.8509% +0.9666% +1.0826%]
       Change within noise threshold.

Instructions per cycle

Criterion reported no significant timing changes.

All benchmarks
Benchmark IPC before IPC after ΔIPC
streams-flow-controlled/walltime/1-streams/each-4194304-bytes 2.20 2.23 +1.3%
streams/walltime/1000-streams/each-1000-bytes 1.97 1.99 +1.1%
streams-flow-controlled/walltime/10-streams/each-1048576-bytes 2.27 2.28 +0.5%
transfer/walltime/pacing-true/varying-seeds 2.24 2.23 -0.4%
transfer/walltime/pacing-false/same-seed 2.24 2.23 -0.3%
streams/walltime/1-streams/each-1000-bytes 1.84 1.85 +0.2%
streams/walltime/1000-streams/each-1-bytes 2.12 2.11 -0.2%
transfer/walltime/pacing-false/varying-seeds 2.24 2.23 -0.2%
transfer/1-conn/1-100mb-resp (aka. Download)/mtu-1504 2.13 2.13 +0.2%
transfer/walltime/pacing-true/same-seed 2.24 2.24 -0.1%
transfer/1-conn/1-100mb-req (aka. Upload)/mtu-1504 2.14 2.14 -0.1%
transfer/1-conn/1-1b-resp (aka. HPS)/mtu-1504 1.81 1.81 +0.1%
transfer/1-conn/10_000-parallel-1b-resp (aka. RPS)/mtu-1504 1.79 1.79 +0.0%

Download data for profiler.firefox.com or download performance comparison data.

Merged via the queue into mozilla:main with commit 5fd2c04 Sep 10, 2026
223 of 227 checks passed
@larseggert
larseggert deleted the fix/cc-app-limited-accounting branch September 10, 2026 09:46
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.

3 participants