Repository navigation
Don't give a slow link's first keyframe up while it can still arrive (851-4477) - #1510
Merged
Merged
Conversation
…-Mac network (851-4477) Reports gain first_picture_ms: in Tier 1 from the first version produced to the first frame the viewer commits, in Tier 2 from the viewer's connect to its first presented frame. The two-Mac benchmark can shape N7 (50 ms, 5% loss, 1 Mbit/s), the only case slow enough for a first keyframe to overlap the connection's start-up. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The host counted a frame lost after six probes spaced by a round trip that was measured before the link's queue built up, and the viewer gave a frame up one round trip after its last packet although its resends were still queued. On a 1 Mbit/s link that turned a first keyframe that lost some packets into a second, larger keyframe. The viewer now keeps waiting while the link is still delivering, and the host treats a NACK as an answer and waits at least as long as the bytes in flight need to cross. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…4477) Review fixes. The viewer waits at most 5 s more while the link delivers, and a complete keyframe or refresh releases the frames of its stream that are still being repaired. The host's count starts again only at a NACK that names a packet it wasn't asked for before, its last wait is at most 5 s, and it reads the acknowledged rate at the present time. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…(851-4477) Second review round. Releasing a tile at its recovery frame made the host answer the released frames with another recovery frame, so it is gone. The viewer's wait while the link delivers is now at most four times the time the frame's own missing packets need, counted from its last packet, and the host fixes its last wait when its sixth probe goes out. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…(851-4477) Co-Authored-By: Claude Fable 5.2 <[email protected]>
…n to have got (851-4477) Co-Authored-By: Claude Fable 5.2 <[email protected]>
…und (851-4477) Co-Authored-By: Claude Fable 5.2 <[email protected]>
… first request as an answer (851-4477) Co-Authored-By: Claude Fable 5.2 <[email protected]>
… the byte count (851-4477) Co-Authored-By: Claude Fable 5.2 <[email protected]>
…nce the reach has passed it (851-4477) Co-Authored-By: Claude Fable 5.2 <[email protected]>
…every sighting (851-4477) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he host's answer, restart and guess rules (851-4477) - The viewer holds a lost frame for other traffic only while that traffic arrives back to back, which means a queue could be ahead of the resend. With gaps between frames nothing is queued: four tiles of video on 50 Mbit/s held a packet that never arrived 218 ms after its request in the sim; now 66 ms. - A repeat the host sends again counts as the viewer answering, so the host doesn't run out its probes on a frame the viewer is still asking for. - The arrival tracker starts its count again only once its reach has passed everything sent, and keeps what is known lost, instead of restarting whenever no frame is in flight. - A whole-frame request no longer marks the frame as guessed past what was sent. - The two-Mac plan check budgets the 90 s ready wait for runs on the 1 Mbit/s network. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cker early only on a measured rate (851-4477) What the code review of the last commit found: - The back-to-back gap floor is the viewer's tail wait instead of a fixed 1 ms, so bursty delivery (Wi-Fi aggregation) still counts as a queue. - The arrival tracker skips a restart only when the link has been measured; before that, sightings across app-limited gaps understate the rate. A real restart clears the loss total again, so an over-count can't stick. - A fast-link test shows the hold still works: a resend queued behind another tile's 1.5 MB keyframe is waited for. - The gap test steps whole frame intervals and names its lost frame directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
pondorasti
force-pushed
the
alexandru/851-4477-keyframe-give-up
branch
from
November 27, 2026 18:32
74f444a to
1679f46
Compare
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of 851-4477 (screen sharing freezes briefly while scrolling on a lossy network). This PR is the first keyframe on a slow link. The clumped-delivery PR comes later; the estimate collapse on the 50 Mbit/s network is 851-4501.
What was wrong
On a 1 Mbit/s link a tile's first keyframe (about 190 KB) was declared lost about when its last packets arrived, and the host answered with a second, larger keyframe. Three things added up:
What changes
All of it is in the Rust transport (
codevisor-media), so the shipped encoder (VCP behind the rate switch) and the fallback get the same code.The crate README has the full description and the numbers behind each choice.
The trade on a 1 Mbit/s link
On a 1 Mbit/s link this PR trades long stalls for short hitches:
The likely cause, not proven: this PR waits for a slow frame to finish crossing the link, where main gives it up and refreshes. Each slow frame then shows as one 250–500 ms gap, instead of fewer, longer stalls while a refresh is requested and sent.
The tables are below: "Fixed-threshold gaps" has the 250/500 ms split, and the first 1 Mbit/s table has keyframes, give-ups, first picture and freezes.
Lab (tamale, same-slot pairs)
1 Mbit/s network, scroll, six repetitions, main at 49aa60a against 74f444a. Runs 46033888710/46034691778 (fallback) and 46035491044/46036614459 (shipped).
First-picture timing is new in this PR, so main's build doesn't record it; main's earlier runs on this network showed 2.7–14.3 s. The freeze counter flags a gap three times the average of the last 30 gaps, so a faster stream with shorter stalls gets more of them flagged. The earlier pair below shows the same rise.
Fixed-threshold gaps, same network and scene, six repetitions (runs 46046692081/46047309465 fallback, 46048049753/46048777518 shipped). Both sides carry #1512's gap count: #1512's head (cbdcb49) against this PR's commits on top of it (lab branch 16e7219, the same tree as this PR's head after the rebase onto main). Median per run, range in brackets:
This PR has about twice as many gaps between 250 and 500 ms, and fewer and shorter gaps over 500 ms.
Earlier pair, before #1508 and before your review's fixes, scroll and video: runs 45917034388 and 45917909821 (fallback), 45924480340 and 45925299171 (shipped).
All seven simulated networks, both encoders, one repetition each. Runs 45907401490/45910867266, 45914887801/45915977188, 45918777916/45920462091 and 45922155291/45923418670. On the good, lossy, burst-loss and 30 Mbit/s networks, latency, updates/s and freezes are unchanged within noise, and first picture stays at 43–132 ms.
50 Mbit/s jittery network (25 ms ± 5, 0.1% loss), six repetitions, main at 49aa60a against 74f444a (after the fixes from your review). Runs 46028957018/46030099696 (fallback) and 46031274586/46032439045 (shipped).
Latency is unchanged except shipped video, p95 59.3 → 64.9 ms. There the rate switch to the fallback encoder fired in 2 of 6 runs on main and 5 of 6 here; in the pair before the fixes it was 5 on main and 3 here, so that count is noise between runs.
The pair before your review's fixes (main at 15a46a3, runs 46001609754/46003118246 and 46004287387/46005429801) had fallback scroll at 9 → 14 freezes and shipped video at 3 → 14. That shipped-video gap is gone; the remaining differences are one or two runs either way.
Why the freezes on the 50 Mbit/s network are not this PR (851-4501). They all come from a rate-estimate collapse that main has too:
In 16 interleaved local traced runs (fallback scroll on that network), the collapse started the same way every time:
The real network lost 13–14 packets per 30 s run in those traces. So the lab gap is which runs hit the trigger, not this change. 851-4501 takes it.
Tests
New sim tests in
tests/core.rs(each fails without the change), covering:Unit tests: the arrival tracker (
arrived.rs), a repeat the host sends again counting as an answer, and a whole-frame request not marking the frame as guessed. A script test (tier2-plan.test.mjs) covers the plan budget.One assertion changed on purpose:
the_viewer_waits_a_little_longer_while_other_tiles_arrive…required the viewer to hold a lost frame for over two give-up times while another tile's video arrived with gaps. Your review found that hold behind the 50 Mbit/s freezes, so it's replaced by the four-tile test above, which requires the opposite.Run locally (M1 Pro, with timeouts):
cargo test -p codevisor-media(50 unit, 57 sim, 6 session), plus clippy.ScreenSharingV2Tests206,ScreenSharingBenchTests98 andCodevisorBenchTests61;swift:format:checkandswift:lint.ScreenSharingV2Tests206 (including the hardware encoder suites on VCP and VideoToolbox),ScreenSharingBenchTests96,CodevisorBenchTests59. One run of four timed out inScreenSharingV2HostContentIntervalTests.eachTileCarriesTheTimeSinceItsOwnContentChanged, a Give VCP frames the bits for their content interval, not the wait before them (851-4499) #1508 test on main that this PR doesn't touch; three more full runs and five runs of that suite passed.node --teston the bench scripts.Code review
Your review at a1c566d. All five are fixed:
Code-review skill on the fixes. Five fixed:
Three left:
Still left from the round before your review:
Not measured
🤖 Generated with Claude Code