From 09df9c09b223f9e185e7c8772ce967c1a4655389 Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 16 Sep 2026 02:34:28 -0700 Subject: [PATCH] input-capture: README states the real per-event lock counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QA finding 3: the Assumptions bullet claimed "three acquisitions per event at most (snapshot, virtual cursor, counters)", which named neither `Screens` nor `CaptureQueue` and undercounted every path. Replaced with the four lock objects the callback can reach and the count on each of the four paths — local key 2, local move 3-4, remote key 3, remote move 5-6 — counted from the code, with the extras (unmapped key, hotkey, escape, modifier transitions) spelled out. Co-Authored-By: Claude Opus 5 (1M context) --- docs/features/input-capture/README.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/features/input-capture/README.md b/docs/features/input-capture/README.md index 5c3e754..a49ede3 100644 --- a/docs/features/input-capture/README.md +++ b/docs/features/input-capture/README.md @@ -36,8 +36,25 @@ code does not enforce is here. the destination is remote, convert to `CapturedInput`, push and swallow (`InputHook.cs:361-368` keyboard, `:322-325` mouse); if local, push mouse *moves only* so `Edge` can watch for a crossing, and pass everything through. - Three uncontended `OSAllocatedUnfairLock` acquisitions per event at most - (snapshot, virtual cursor, counters) and no allocation (invariant 4). + No allocation on any of it (invariant 4). +- **Four locks are reachable from the callback**, all uncontended + `OSAllocatedUnfairLock`s held only for a struct copy: `EventTap.counters`, + `RoutingState`'s box (the snapshot *and* the virtual cursor share it), + `Screens`' layout and `CaptureQueue`'s ring. Counted from the code, per + event, on the four paths that matter: + - **local key**: 2 — `counters`, snapshot read. An unmapped key adds one + `counters`; a matched hotkey adds one ring push, and an escape hotkey one + more `RoutingState` write. + - **local mouse move**: 3 — `counters`, snapshot read, virtual-cursor write; + 4 when Easy Mouse lets the move be offered as an `.edgeCandidate` (one ring + push). `Screens` is not read on this path. + - **remote key**: 3 — `counters`, snapshot read, one ring push. A + `flagsChanged` pushes once per modifier transition instead, and twice more + for a Caps Lock toggle. + - **remote mouse move**: 6 — `counters`, snapshot read, virtual-cursor + advance, `Screens`' layout, then two ring pushes (`.mouse` and + `.edgeCandidate`); 5 when the candidate is suppressed. This is the worst + path in the file. - **Swallowing is a separate flag from the destination.** ALL-machines mode sends input to every peer *and* keeps it locally (`InputHook.cs:361`), so `swallowKeys`/`swallowMouse` are set by the Engine, not derived here.