Skip to content

perf(emoji): cache caret session state#507

Closed
JustYannicc wants to merge 1 commit into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-emoji-caret-session
Closed

perf(emoji): cache caret session state#507
JustYannicc wants to merge 1 commit into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-emoji-caret-session

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

  • Added an emoji caret session snapshot that captures the frontmost PID, bundle id, focused AX element, and caret rect from the first successful query character.
  • Reused the cached caret/bundle payload for subsequent emoji query updates and backspaces while the event target PID remains stable.
  • Invalidated the cache on dismiss/reset, PID changes, secure fields, and no-rect AX results.
  • Added a focused Swift-backed cache test that runs through the existing node --test 'scripts/test-*.mjs' suite.

Why

The native emoji trigger monitor previously asked NSWorkspace.shared.frontmostApplication and AXCaretQuery.current() for every emitted query update. Typing a multi-character emoji search could therefore repeat frontmost and Accessibility caret work on every character/backspace.

Metrics

Focused stubbed measurement for typing :fire plus one backspace:

Path Query emits Frontmost lookups AX caret queries
Before 5 5 5
After cached rect path 5 1 1

No-rect results intentionally do not cache, so those continue to re-query until a usable rect is available or the session is dismissed.

Validation

  • swiftc -O -o /tmp/supercmd-native-check/emoji-trigger-monitor src/native/emoji-trigger-monitor.swift src/native/ax-caret-query.swift src/native/emoji-caret-session-cache.swift -framework AppKit -framework ApplicationServices
  • node scripts/test-emoji-caret-session.mjs
  • node --test 'scripts/test-*.mjs' (passes; live Electron crash-recovery test is skipped in this environment)
  • ./node_modules/.bin/tsc -p tsconfig.main.json
  • node scripts/check-i18n.mjs (strict locales pass; pre-existing Italian missing-key warnings remain)
  • git diff --check

Notes and risks

  • SourceKit LSP sees the Swift files in isolation and reports companion-file symbols as missing; the direct multi-file swiftc compile is clean.
  • node scripts/build-native.mjs compiled the Swift helpers, then failed in the existing native addon step because node-addon-api was unavailable under this machine's pnpm/npx wrapper setup.
  • The cached path assumes normal CGEvent target PID availability. If the PID is missing, the monitor falls back to one frontmost PID lookup while a cached session is active to avoid reusing state across app switches.

@JustYannicc JustYannicc changed the title [codex] Cache emoji caret session state perf(emoji): cache caret session state Jul 3, 2026
@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Superseded by the consolidated renderer performance PR #533: #533. Closing this scoped source PR so review stays centralized there.

@JustYannicc JustYannicc closed this Jul 3, 2026
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