Skip to content

perf: skip the shortcut walk for modifier sets no shortcut uses - #393

Merged
arzafran merged 2 commits into
mainfrom
perf/shortcut-early-exit
Sep 30, 2026
Merged

arzafran merged 2 commits into
mainfrom
perf/shortcut-early-exit

Conversation

@arzafran

Copy link
Copy Markdown
Member

What this does

Typing capital letters, shifted symbols and Option characters gets cheaper per key. Those key presses used to check all 57 shortcut actions one by one, even though no shortcut uses Shift alone or Option alone. Now the app keeps the set of modifier combinations that any shortcut starts with, and skips the whole check when a key press uses a combination outside that set.

Plain typing is unchanged: it already skipped the check.

How it stays safe

  • Every shortcut matcher compares modifiers first, so a key whose modifiers aren't in the set can't match anything.
  • The set includes the hardcoded Ctrl+Tab and Ctrl+Shift+Tab, and the Ghostty split-navigation shortcuts are checked live.
  • A pending two-key chord always runs the full check.
  • The set is rebuilt whenever shortcuts change: in Settings, by reset, or by a settings.json reload. Until it is first built, nothing is skipped.

Measured

Debug build, 20 batches of 1000 synthetic key presses, median per key, 3 runs each (numbers are from the whole shortcut handler).

Key Before After
Shift+A 165-166 µs 66-69 µs
Shift+: 162-220 µs 67-68 µs
Option+A 169-220 µs 67-69 µs
Cmd+Shift+Y, Ctrl+K (shortcut modifiers) unchanged unchanged

Debug numbers overstate absolute cost; the ratio is the point. The benchmark harness is not included.

Test plan

  • AppDelegateShortcutRoutingTests pass in CI.
  • Capital letters, symbols and Option characters type normally in a terminal and the browser address bar.
  • A shortcut changed to an unusual modifier set in Settings works right away without restarting.

@arzafran
arzafran merged commit 4fba126 into main Sep 30, 2026
13 checks passed
@arzafran
arzafran deleted the perf/shortcut-early-exit branch September 30, 2026 20:34
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