Skip to content

perf(paste): paste about 136 ms sooner and stop blocking on YOLO Return - #3084

Merged
kitlangton merged 1 commit into
devfrom
fast-paste-sub25ms
Nov 29, 2026
Merged

kitlangton merged 1 commit into
devfrom
fast-paste-sub25ms

Conversation

@kitlangton

Copy link
Copy Markdown
Collaborator

Dictations paste about 136 ms sooner on macOS, and a YOLO dictation finishes when its text lands instead of 500 ms after release.
Every paste used to sleep 100 ms after ⌘V and pace ⌘V's four key events 15 ms apart, and a YOLO send held the output worker through its Escape window. Remote desktop and VM clients keep the slow pacing, and the clipboard restore is unchanged.

❌ Before

  1. Paste writes the clipboard, posts ⌘V with 15 ms between events (45 ms).
  2. ❌ Sleeps 100 ms so the app can read the clipboard, even when no paste follows.
  3. ❌ YOLO: sleeps on the output worker until 500 ms after release, then 100 ms more after the paste on slow runs (the settle counted twice), then presses Return.
  4. ❌ History writes and fsyncs history.json before the dictation finishes.

✅ After

  1. Paste posts ⌘V 3 ms apart in a local app (9 ms). Remote desktop, screen sharing, VM clients, and unnamed apps keep 15 ms.
  2. Returns right after ⌘V. Only a next paste or clipboard change waits out what is left of the 100 ms.
  3. YOLO: the output worker keeps taking jobs and presses Return when its window ends. Escape, another app in front, or a newer dictation or paste means no Return, and History relabels the entry as a dictation.
  4. History records in memory. Its existing worker saves the file right after, coalesced, and flushes on stop.
- post ⌘V (15 ms gaps) -> sleep 100 ms -> [YOLO] sleep to 500 ms -> Return -> fsync history
+ [wait rest of last paste's 100 ms, if any] -> post ⌘V (3 ms gaps local) -> done
+ [YOLO] worker loop wakes at deadline -> Return only if no Escape, same app, no newer job
+ history worker saves in the background; last handle and output worker flush on stop

📊 Numbers: fixed waits removed per paste, from the code (not measured end to end)

Wait on the paste path Before After
Settle after ⌘V (macOS, Linux) 100 ms 0 ms (lone paste)
⌘V event gaps, local app (macOS) 45 ms 9 ms
YOLO wait inside paste_ms 190 to 350 ms 0 ms
Snapshot on a back-to-back paste full clipboard read skipped

Also in this PR:

  • A back-to-back paste skips the clipboard snapshot while the earlier paste's restore still holds the user's clipboard. A user copy in between is still never clobbered (changeCount guard).
  • Unfulfilled file promises are not read for the restore: reading one makes the source app write the file, and Hex could never fulfil a restored copy.
  • The Chromium 155/156 framework scan runs once per running process, not on every paste.
  • paste_ms keeps its name and meaning (the whole output step). New fields: text_paste_ms, history_ms, and yolo_wait_ms on "YOLO mode pressed Return".

New tests cover settle timing, back-to-back snapshot skip and user-copy preservation, the file-promise guard, local versus remote key gaps, the YOLO deadline, Escape, app-change and cancel paths, and the History relabel and flush.

👀 Read: the output worker loop in parakeet.rs (recv_timeout against the pending Return, and the cancel on any job) and the deferred save in history.rs (sync saves an unsaved record before any reread, so a reread can never drop one). The rest is routine.

From a 48-hour log audit of paste latency · no user reports · Linux and Windows compile through CI

Checks run
  • scripts/check paste keyboard output_history pending_return yolo_mode history dictation::modes::output correction_watch plus the YOLO, Paste Last and salvage cases in parakeet::tests: 290 passed
  • cargo clippy --locked --bin hex -- -D warnings (macOS): clean
  • python3 scripts/code-shape.py: no hard problems

…aster, and stop blocking on YOLO Return

- Lazy settle gate shared by macOS and Linux: a paste returns once its key
  goes; only the next clipboard change waits out the rest of 100 ms.
- Skip the clipboard snapshot while the last paste's restore still holds the
  user's clipboard; never read unfulfilled file promises.
- 3 ms between Cmd+V events in local apps, 15 ms kept for remote desktop,
  screen sharing, VM clients, and unnamed apps.
- YOLO Return waits on the output worker's loop instead of a sleep; Escape,
  another app in front, or a newer job means no Return and History relabels.
- History saves records in the background, coalesced, flushed on stop.
- Log text_paste_ms, history_ms, and yolo_wait_ms beside paste_ms.
@kitlangton
kitlangton merged commit e45e2a3 into dev Nov 29, 2026
4 checks passed
@kitlangton
kitlangton deleted the fast-paste-sub25ms branch November 29, 2026 06:19
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