Gate switcher shortcut event peek behind session HID counters#1397
Merged
steipete merged 2 commits intoJun 10, 2026
Conversation
d401de7 to
aa0d94c
Compare
Co-authored-by: bcssewl <samirbassel@gmail.com>
d053d90 to
96d5848
Compare
Owner
|
Landed in Verification:
Caveat: the installed Thanks @bcssewl! |
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.
Refs #1321, #1325, #1308 (merged-menu interaction lag family).
Summary
ProviderSwitcherShortcutEventMonitor'sCFRunLoopObserverfires on.beforeSourcesof every pass of the menu-tracking run loop, and every firing calledNSApp.nextEvent(matching:until:inMode:dequeue:false)to peek the queue for switcher shortcuts and clicks. Menu tracking spins once per mouse move, so hover-heavy interaction paid that AppKit peek continuously.This PR adds a tiny gate in front of the peek: read the session-wide HID event counters (
CGEventSource.counterForEventType(.combinedSessionState, ...)) for the monitored kinds (keyDown,leftMouseDown,leftMouseUp) and skip the peek when none advanced since the previous pass. Mouse moves never advance those counters, so the common hover pass reduces to three cheap counter reads; actual key presses and clicks open the gate on the same pass they occur, so shortcut behavior is unchanged with zero added latency.Evidence
A 60-second
sampleof a packaged build during ordinary merged-menu interaction (Apple Silicon, real multi-provider config) attributes 1,348 main-thread samples to this peek path —CFRunLoopObserver thunk → ProviderSwitcherShortcutEventMonitor closure → NSApp.nextEvent(StatusItemController+ProviderSwitcher.swift:24-25) — nearly as much as the entire open-menu rebuild subtree in the same trace (1,565). It's pure overhead on passes with no pending key/click, which is almost all of them while the cursor is moving.Validation
swift testfull suite: green except the known rotating locale/load flakes (MiniMaxMenuCardModelTests,HistoricalUsagePaceOwnershipTests,OpenAIDashboardWebViewCacheTests) which reproduce identically on cleanmainand pass in isolationmake check: 0 violationsswift build,swift test,make checkIndependent of #1394 (no shared files); the two compose.