Repository navigation
A window reads its display's refresh grid without the registry's lock - #616
Merged
Merged
Conversation
`DisplayLink::refresh_phase` runs once or twice a frame (the latch's grid and the align wait before handover). It locked the link registry, the mutex the CoreVideo thread holds through every callback, and read the clock twice. The grid (last refresh, period) is now its own pair of atomics shared between the display's entry and the windows on it, read lock-free, with one host-clock read: the phase is of the moment of the call, which both callers already passed as `Instant::now()`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Instruction counts (cachegrind, exact) against
|
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.
This is the guard trim deferred from #552.
DisplayLink::refresh_phaseruns on every steady frame: once for the latch's grid and once for the align wait before handover. Each call locked the link registry, the mutex the CoreVideo thread holds through every callback, and read the clock twice.What changes:
Arc<Grid>of two atomics. The display's entry and the windows on it share it, andfollow_displayswaps it when a window changes screens.refresh_phase(fresh)reads it without the lock and with onemach_absolute_time. The phase is that of the moment of the call; both callers passedInstant::now()there anyway.atparameter is gone. It was crate-internal, so no public API changes.Same behaviour: the same grid and the same phase, give or take the nanoseconds between the two clock reads it used to make. Without the lock, a reader can see a period from one callback beside a refresh time from the next. That can only matter while the display changes mode, and the comment says so.
Measured: animate, dist, 6 alternating 4 s runs each,
/usr/bin/time -l.Both are within run-to-run noise (about 2.5% between runs). The cut is about 100–200 instructions a frame plus one lock the link thread contends for, too small to resolve here. It removes UI-thread versus link-thread lock contention from the frame's handover path rather than buying a measurable instruction win.
Tests:
cargo test -p zgx-desktop, clippy 1.99-D warnings, fmt.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.