Repository navigation
Capture the shared display at its full rate, and let the viewer keep up (851-4475) - #1506
Merged
pondorasti merged 6 commits intoNov 27, 2026
Merged
Conversation
pondorasti
added a commit
that referenced
this pull request
Nov 27, 2026
…s race (851-4475) From the code review of #1506: - a newer frame the render worker took is drawn next when its draw fails or it can't be drawn into that drawable, instead of being lost - a redraw asked for while the viewer holds a frame to catch up is drawn when the hold ends - a refresh-rate follow that fails after the capture restarted keeps the new capture's cadence, and every start sets its own refresh source - the host applies a refresh-rate change after a capture resize in flight - the viewer's refresh period follows a refresh change on the same screen Co-Authored-By: Claude Opus 5.5 <[email protected]>
pondorasti
force-pushed
the
alexandru/851-4475-screen-sharing-host-captures-a-frame
branch
from
November 27, 2026 05:33
ec8421d to
1527d68
Compare
A full-rate stream left the macOS viewer waiting for a drawable on every frame, so each frame showed a refresh later. The render coordinator now skips one frame, at most once a second, when a full-rate stream had to wait for a drawable, and the render worker draws the newest frame that arrived while it waited. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ScreenCaptureKit delivers about 0.8 ms later than its minimum frame interval, so the 1/60 s cap took 57.3 frames a second on a 60 Hz display and each frame reached the engine later than the last. The cap now follows the display's refresh rate: 1/480 s up to 60 Hz, and at most 60 frames a second with headroom on faster displays, so a 120 Hz host is captured at every other refresh. The host follows a refresh-rate change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s race (851-4475) From the code review of #1506: - a newer frame the render worker took is drawn next when its draw fails or it can't be drawn into that drawable, instead of being lost - a redraw asked for while the viewer holds a frame to catch up is drawn when the hold ends - a refresh-rate follow that fails after the capture restarted keeps the new capture's cadence, and every start sets its own refresh source - the host applies a refresh-rate change after a capture resize in flight - the viewer's refresh period follows a refresh change on the same screen Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rival counting (851-4475) - a refresh rate that can't be read mid-session keeps the capture's cadence; only a capture start falls back to the 120 Hz rule - the host follows the refresh rate in its own task, which ending the session cancels, so the session's resize stays cancellable, and logs failures - refresh rates just over a multiple of 60 round to that multiple - the viewer's catch-up counts every frame the mailbox receives, timed when it is put, including frames a newer one replaced - cadences compare by interval, so 60 and 59.94 Hz only relabel - capture reconfigurations run one at a time, each with the newest size and cadence Co-Authored-By: Claude Opus 5.5 <[email protected]>
pondorasti
force-pushed
the
alexandru/851-4475-screen-sharing-host-captures-a-frame
branch
from
November 27, 2026 07:21
1527d68 to
6a94f7f
Compare
…d merge bursts (851-4475) From the code review of the previous commit: - each capture start begins a new reconfiguration queue, so one stuck on a stopped stream never holds up the restarted one - a reconfiguration waits inside its turn for a start in progress - the cursor, dynamic range and audio settings change only in their own turn, so an earlier turn never applies them - the catch-up counts puts less than half a refresh apart once, so a VNC burst or the tiles of one update don't look like a full-rate stream - the refresh-rate rounding uses a 1% tolerance, so 60.6 Hz counts as 60 - a newer refresh-rate follow cancels the one before Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l-rate frames (851-4475) From the review of 481b0d1: - a reconfiguration checks which queue is current after it has waited for a start, so it never runs beside the next start's queue - the catch-up needs the newest arrival to be recent and counts only commits of new frames, so a redraw long after a scroll can't hold the next keystroke - a commit whose frame the render worker already swapped for a newer one doesn't start a hold, so the viewer never skips two frames - setDynamicRange compares inside its turn, so a second call isn't dropped - frames replacing the held one during a hold count as superseded - a newer frame the renderer can't make textures for is dropped, not held Co-Authored-By: Claude Opus 5.5 <[email protected]>
pondorasti
deleted the
alexandru/851-4475-screen-sharing-host-captures-a-frame
branch
November 27, 2026 10:29
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.
Fixes 851-4475
The Mac host now captures the shared display at its full rate, and the viewer keeps up with a stream that brings a frame every refresh. In the four-way lab comparison this put Codevisor level with Apple High Performance on scroll, window drag and typing, at 60 updates a second, for 1.5 to 3 points of a core on the host.
Changes
ScreenSharingCaptureCadence). The encoder stays at 60.maximumFramesPerSecond, or else the display mode. Unknown at a capture's start counts as 120 Hz; unreadable later keeps the current cadence. The host re-reads it when the screen parameters change, in its own task that ending the session cancels, and reconfigures only when the interval changes. The capture applies reconfigurations one at a time; each setting changes only in its own turn, a turn waits for a start in progress, and each start begins a new queue.Proof
alexandru/851-4475-cadence-confirm, this PR's first two commits plus one lab commit; the review-fix commit came later and changes only race paths this run doesn't exercise). Image age p50 / p95 ms, median of 2 repetitions:alexandru/851-4475-cadence-confirm2). Image age p50 / p95 ms, before → after:bun run build:ios).ScreenSharingV2EncoderKind.configured(), VCP behind the rate switch) and the fallback, fed every refresh at 60 Hz and at most 60 a second at 120 Hz.Code review (medium) and what was fixed
Each fix has a test that fails without it.
Your review (high) of 1527d68, and what was fixed
Each item has a test that fails on the old code.
session.resizing, so ending a session cancelled only the follow. It now has its own task, whichendcancels. A newer follow also cancels the one before.framesPerSecondremoved.Code review (high) of that fix, and what was fixed
Smaller ones, also fixed: the 60.5 to 61 Hz rounding, a newer follow cancels the older, tests now assert the refresh rate rather than interval-only equality, and the resize-race test asserts the follow is queued rather than relying on timing.
Left: turning audio on mid-session still restarts the stream outside the queue, so a resize in flight can be lost. That was already the case before this PR.
Your review (medium) of 481b0d1, and what was fixed
setDynamicRangenow compares inside its turn, so a second call isn't dropped.renderFramesDroppedAfterDrawableWait), not held.Each of 2 to 6 has a test that fails on the old code.
Not checked
🤖 Generated with Claude Code