Skip to content

Remember the gaps inside frames for 10 s, and add two clumped benchmark networks (851-4477) - #1517

Merged
pondorasti merged 6 commits into
mainfrom
alexandru/851-4477-clumped-delivery
Nov 28, 2026
Merged

pondorasti merged 6 commits into
mainfrom
alexandru/851-4477-clumped-delivery

Conversation

@pondorasti

@pondorasti pondorasti commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Part of 851-4477 (screen sharing freezes briefly while scrolling on a lossy network). This is the clumped-delivery part (Part A). #1510 and #1515 covered the slow-link start and the 50 Mbit/s collapse.

What was wrong

Some links deliver in clumps: Wi-Fi, or a busy receiver, holds packets and lets them out together. The viewer waits a little for a frame's tail (1.5 × the longest recent gap between a frame's packets). That gap faded within about 0.7 s, and most frames are a few packets inside one clump, so they show no gap. By the next large frame the wait was back at 1 ms. The gap to the next clump then passed for a lost tail, and the viewer asked for the packets it expected by then, 28 at a time, every millisecond.

The host resent them and took the requests for loss. In the sim (N3 with a 4 ms or 10 ms release tick), main resent 215–460 packets that were still on their way. The loss window read 16–19% and cut the estimate, which then sat near 11 Mbit/s on a 1 Gbit/s link in 2 of 3 seeds, with captures refused.

#1515 doesn't cover this. A clump holds a packet longer than half of N3's 2 ms round trip, so it isn't recognised as a late original.

What changes

  • Two clumped benchmark networks. N8 and N9 are the lossy network (N3) with a 4 ms and a 10 ms release tick: a packet leaves the link at the next tick. The Rust sim (netsim) and the Tier 1 relay (BenchNetworkModel) model them the same way, and the nightly matrix runs them. The impaired transport's round trip includes half a tick each way. A tick too small or too large to represent leaves arrivals unchanged.
  • The viewer remembers the gaps it has seen inside frames for 10 s instead of letting them fade, and the memory expires by the clock. Each gap counts at most twice the round trip (or eight packet paces, if longer). So one stall inside a frame can't hold every lost tail's first request back by its length for 10 s. So a clump gap it has seen keeps the tail wait long enough. In the sim on N8 and N9: 5–13 resends instead of 215–460, at most 2 requests per run for packets still on their way, no refused captures, and the estimate's low stays at 104–114 Mbit/s, as on N3.

What the earlier plan had that this drops

  • Asking only for gaps already seen, i.e. no requests for tail packets expected by now. Turning the tail requests off entirely broke 19 sim tests. They carry the slow-link give-up and lost-tail repair from Don't give a slow link's first keyframe up while it can still arrive (851-4477) #1510. Remembering the gaps gets the clumped case without that.
  • Counting loss from what the viewer reports missing. Don't count a request for a packet that was only late as loss (851-4501) #1515 already takes back what the viewer reports was only late, and the gap memory stops the spurious requests on clumped links. With both, the sim's loss windows on N8 and N9 read 0.4–2.5%.
  • Not rebuilding the estimate from frames of a few packets. No sim case needs it now. In the lab the estimate still dips to about 5 Mbit/s early in most 4 ms-tick scroll runs, on main as much as with this PR, without freezes or long gaps. See "Left" below.
  • The old branch's looser floor for the tiled-keyframe sim test. It isn't needed on today's main.

Lab (tamale, same slot)

Main plus only the networks commit (6aa7333) against this branch (081533e).

  • Tier 1, 30 s runs: N3, N8 and N9 with typing, scroll and video, 3 repetitions; N7 scroll and video, 6 repetitions; both encoders. Runs 46101209090/46102846148, 46104520679/46105183780 (fallback), 46105869062/46107103370, 46108343887/46108994220 (shipped).
  • Tier 2 (two Macs) on N3, scroll, 3 repetitions per system. Runs 46109648764/46110951374.

Sums over the repetitions, main → this PR:

Network, scene Encoder Freezes Gaps over 250 ms Gaps over 500 ms Packets resent
N3 (all three scenes) both 0 → 0 0 → 0 0 → 0 150 → 22
N8 scroll fallback / shipped 5 → 0 / 2 → 0 1 → 0 / 0 → 0 0 → 0 1171 → 362 / 1321 → 261
N9 scroll fallback / shipped 6 → 0 / 0 → 0 5 → 0 / 0 → 0 0 → 0 1492 → 278 / 2024 → 288
N8, N9 video both 0 → 0 0 → 0 0 → 0 1878 → 2221
N8, N9 typing both 0 → 0 0 → 0 0 → 0 38 → 44
N7 scroll fallback 101 → 104 107 → 90 9 → 12 812 → 782
N7 scroll shipped 86 → 115 111 → 121 18 → 9 1132 → 817
N7 video fallback / shipped 57 → 46 / 63 → 54 43 → 37 / 46 → 45 27 → 27 / 32 → 32 829 → 721 / 1047 → 545
Two-Mac N3 scroll both 0 → 0 0 → 0 0 → 0
  • Latency: e2e p95 is unchanged within 1 ms on N3, N8 and N9. Two-Mac image age p50 is 49 → 47 ms (fallback) and 32 → 31 ms (shipped).
  • 1 Mbit/s (N7): updates/s go 13.8 → 24.5 (fallback scroll) and 11.5 → 11.6 (shipped scroll). Gaps over 500 ms and frames given up move in opposite directions on the two encoders: 9 → 12 and 2 → 5 on fallback, 18 → 9 and 5 → 4 on shipped. In the sim at 1 Mbit/s neither side gives up a frame, and this PR resends 24–43 packets against 39–54.

Tests

  • Sim: a_link_that_delivers_in_clumps_isnt_asked_for_packets_still_on_their_way covers N8 and N9 with 3 seeds each: at most 3 early requests, at most 20 resends, no refused captures, and the estimate stays at or above 100 Mbit/s. It fails on main.
  • Gap memory: a gap older than 10 s no longer delays the request for a lost tail, and the memory expires by the clock on a quiet stream.
  • Network model: tick tests in Rust and Swift, plus a huge and a tiny tick.

Two existing assertions changed:

  • a_slow_link_doesnt_ask_again_for_packets_still_on_their_way required early requests to be at most 5% of resends. The early count is the same as on main (1 per seed), but resends dropped from 29–35 to 19–25, so 1 of 19 failed the ratio. It now requires at most 1 early request.
  • jitter_without_a_queue_doesnt_pull_the_estimate_down is loosened: one seed over 30 Mbit/s became five seeds over 26, just under the new measured low (26.4). On N3 with 1 ms jitter the estimate's low is 26–29 Mbit/s against 30–31 on main, while resends drop from 19–45 to 4–7. Main's early requests cut the jitter-delayed packets out of each frame's first-time bytes, which shortened the frame's spread and raised its rate sample. Now they count where they arrived. The stream needs 2.9 Mbit/s, and admission never refuses. The crate README has these numbers.

Run locally (M1 Pro, with timeouts):

  • Rust: cargo test -p codevisor-media (83 unit, 65 sim, 6 session tests), plus clippy.
  • Swift: ScreenSharingV2Tests 206, ScreenSharingBenchTests 100, CodevisorBenchTests 61, plus swift:format:check and swift:lint.

Code review

Four findings:

  • Important: the jitter estimate. Measured, explained and written into the README; the test change is above.
  • Fixed: the impaired transport's round trip without the tick.
  • Fixed: degenerate ticks.
  • Fixed: docs and help text saying N0–N7.

Your review at 081533e.

  1. One outlier gap set the tail wait for 10 s. Each gap now counts at most twice the round trip, or eight packet paces if longer. A receiver test has a 30 ms stall at a 2 ms round trip: the tail wait is at most 6 ms, against 25 ms (the give-up time) without the cap. Clump gaps within the round trip still set it. The clumped and jitter sim results are unchanged, so no lab rerun. Counting a gap only once it recurs (the longest unless it's over twice the second longest, or the second longest) broke the clumped and 1 Mbit/s sim tests: in 10 s on N8 the memory held a single clump gap, because most frames fit inside one clump.
  2. The jitter floor is 26 Mbit/s.
  3. The Swift model leaves arrivals as they are for a tick too small, too large or infinite, and checks the multiplication for overflow. There is one parameterized test for all three.
  4. One NetworkConditions::release_tick() is used by both the sim and ImpairedTransport::rtt().
  5. The sim's next tick falls back to the arrival when it doesn't fit in 64 bits, with a test.
  6. The ScreenSharing README now says matrix is N0–N7 and all adds N8 and N9.
  7. matrix-v2 stays. Baselines are looked up per cell (system, scene, network) from nightlies of the same tier and method, not by plan name. A cell with no nightlies has no reference, so the gate doesn't judge it except for errors; BenchRegressionGateTests covers that. The results table shows "–" against nightlies until they exist, and the existing cells' baselines are unchanged.

Left

  • The early estimate dip on N8. In the lab it falls to about 5 Mbit/s early in most 4 ms-tick scroll runs, on main and with this PR alike, without freezes or long gaps. That is where the dropped change 3 would apply, if it matters.
  • A lost tail waits longer. One long stall inside a frame holds the tail wait at up to the give-up time for 10 s, so a lost tail is asked for that much later.

🤖 Generated with Claude Code

pondorasti and others added 6 commits November 27, 2026 22:13
N8 and N9 are the lossy network with a 4 ms and a 10 ms release tick: a
packet leaves the link at the next tick, so packets arrive in clumps as
they do behind Wi-Fi or a busy receiver. Both the Rust simulation and the
Tier 1 relay model them, and the nightly matrix plan runs them.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The viewer's wait before it asks for a frame's tail followed the longest
recent gap between a frame's packets, but forgot it within a second. On a
link that delivers in clumps the gap to the next clump then passed for a
lost tail, the viewer asked for packets still on their way, and the host
took the requests for heavy loss and cut its estimate.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… (851-4477)

Review fixes: the 10 s window only dropped old gaps when a new one was
pushed, so a quiet stream kept a stale gap; and the Rust network model
divided by a zero tick.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…eir share of fewer resends (851-4477)

With the gap memory the slow-link sim resends 19–25 packets instead of 29–35, and the one request per seed for a
packet still on the link, the same as on main, became more than 5% of them. The test now bounds that count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…te ticks, and write down the jitter trade-off (851-4477)

From the code review:
- ImpairedTransport's round trip leaves out the tick's hold; it now adds half a tick each way.
- A tick too small to count in nanoseconds (Swift) or too large to represent (Rust) leaves arrivals as they are.
- The README gives the gap memory's cost on a jittery link with no queue: an estimate about 7% lower (26–29
  against 30–31 Mbit/s) with resends down from 19–45 to 4–7, and why.
- Docs and help name N0–N9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…helper, and guard the Swift tick (851-4477)

From the review of 081533e:
- One stall inside a frame set the tail wait for 10 s; each gap now counts at most twice the round trip (or eight
  packet paces). Clump gaps are within that; the clumped and jitter sim results are unchanged.
- The jitter test's floor is 26 Mbit/s, just under the new measured low.
- The Swift model leaves arrivals as they are for a tick too small, too large or infinite, and checks for overflow.
- One release_tick() helper for the sim and ImpairedTransport; the sim's next tick falls back when it doesn't fit.
- The ScreenSharing README says matrix is N0–N7 and all adds N8 and N9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4477-clumped-delivery branch from 081533e to 1516759 Compare November 28, 2026 06:17
@pondorasti
pondorasti merged commit 6a5f3ad into main Nov 28, 2026
11 checks passed
@pondorasti
pondorasti deleted the alexandru/851-4477-clumped-delivery branch November 28, 2026 06:45
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.

1 participant