Repository navigation
Pace Wayland clipboard polling by the cost of the last capture - #20
Open
capybaraonchain wants to merge 1 commit into
Open
capybaraonchain wants to merge 1 commit into
capybaraonchain wants to merge 1 commit into
Conversation
Wayland has no usable change notification, so the daemon captures the whole clipboard every poll interval (75 ms by default): every format is read and hashed. With a large clipboard, such as a macOS screenshot synced with its PNG and TIFF forms, one capture takes longer than the interval, so captures run back to back and the daemon uses more than one CPU core until the clipboard changes. After a capture that took more than half the poll interval, wait nine times its cost (three seconds at most) before the next one. Cheap captures keep the configured interval. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
Problem
On Wayland the daemon has no change notification, so it captures the whole clipboard every
poll_interval_ms(75 ms by default), reading and hashing every format. When the clipboard holds something large, one capture takes longer than the interval and the captures run back to back.Seen on an Arch Linux / Hyprland machine paired with a Mac (v0.2.18): after a screenshot was copied on the Mac, the Linux daemon used about 1.2 CPU cores continuously until the clipboard changed. With text on the clipboard it idles at 0%.
Change
After a capture that took more than half the poll interval, the next poll waits nine times that cost, three seconds at most. Cheap captures are not affected and keep the configured interval. The wait is kept across a cancelled
select!round, so another branch running first does not end it early.It is a small change in
Daemon::watch_clipboardplus acapture_pausehelper. Change detection, formats and X11 are untouched; the only cost is that a change to an already large clipboard is noticed up to three seconds later.Measurements
Same machine, Mac screenshot on the clipboard:
Sync in both directions still works.
Tests
Two tests in
src/daemon/tests.rsdrive the real watch loop with a polled backend: an expensive capture (60 ms at a 20 ms interval) is captured about 3 times in 1.5 s (25 times without the change, so the test fails onmain), and a cheap one keeps its interval.cargo fmt --all -- --checkandcargo test --all-targetspass.Disclosure
The diagnosis, the patch and this description were written by an AI assistant (Claude) working on my machine; I ran it there and the numbers above are from that machine. A better long-term fix may be a real change notification on Wayland (for example the data-control protocol's selection events), which would remove the polling entirely; this change only bounds its cost.