Skip to content

perf(terminal): gate the Korean input-source probe on its setting - #13181

Merged
nwparker merged 1 commit into
mainfrom
nwparker/gate-korean-prefetch
Aug 8, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/gate-korean-prefetch

Conversation

@nwparker

@nwparker nwparker commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #13104, from my review there. Non-blocking then, cheap to fix now.

prefetchKoreanInputSource() ran under a bare isMac check, so it was not the Korean feature's cost — it was every macOS user's cost. Each refresh runs /usr/bin/defaults export com.apple.HIToolbox - | /usr/bin/plutil -extract … | /usr/bin/plutil -convert json …, four processes in the main process, on a ≤1-per-2000ms-of-typing cooldown. Input-source toggle keys pass force: true, so a single Caps Lock press costs two probes regardless of cooldown. terminalKoreanWonToBackquote defaults to false (src/shared/constants.ts:349).

keyboard-handlers.ts has no settings in scope, so this threads the flag through KeyboardHandlersDeps from TerminalPane.tsx, which already reads settings. It is in the effect's dependency array deliberately: toggling the setting mid-session re-runs the effect and warms the cache before the first Backquote, so the feature does not silently miss its first keystroke.

I verified the test discriminates rather than just passing — removing the gate makes the setting-off case fail.

Verified: typecheck across all three configs (with config/*.tsbuildinfo cleared first — stale buildinfo has produced false greens here), oxlint clean, terminal-pane 259 files / 2997 tests. No max-lines disable added; the one at the top of keyboard-handlers.ts is pre-existing.

cc @hyein-cbio — no defect in your change, just moving its cost behind its own switch.

Made with Orca 🐋

prefetchKoreanInputSource ran under a bare isMac check, so every macOS user
paid for it. Each refresh shells out to `defaults export | plutil | plutil` —
four processes in the main process — and input-source toggle keys pass
force: true, so one Caps Lock press costs two probes. terminalKoreanWonToBackquote
defaults to false.

Threads the setting through KeyboardHandlersDeps and into the effect's
dependencies, so enabling it mid-session still warms the cache before the
first Backquote.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The terminal passes terminalKoreanWonToBackquote to keyboard shortcut handling. The keyboard handler accepts this setting and gates macOS Korean input-source prefetching. The effect tracks the setting as a dependency. A happy-dom Vitest suite verifies that prefetching is skipped when disabled and invoked when enabled.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and testing, but it omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add all required template sections, state No visual change, record the checked commands, and summarize AI cross-platform and security reviews.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes gating the Korean input-source probe behind its setting.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ee9ba89f-e1c0-42c1-89b8-d909555bb0f1

📥 Commits

Reviewing files that changed from the base of the PR and between 2400393 and d2705b3.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/keyboard-handlers-korean-prefetch-gate.test.tsx
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts

Comment on lines +271 to +275
// Gated on the setting because each refresh shells out to `defaults export | plutil | plutil`
// and the default is off, so an ungated prefetch costs every macOS user four processes.
if (koreanWonToBackquoteEnabled) {
prefetchKoreanInputSource()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift

Stop Korean input-source probing when the setting is disabled.

prefetchKoreanInputSource() installs global focus, keydown, and keyup listeners. After an enabled session, changing the setting to false does not remove or disable those listeners. Later events can still start the four-process refresh.

  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts#L271-L275: add a reversible or reference-counted listener lifecycle, and disable it when the setting becomes false.
  • src/renderer/src/components/terminal-pane/keyboard-handlers-korean-prefetch-gate.test.tsx#L65-L75: add an enabled-to-disabled transition test that verifies the new teardown or gate behavior.
📍 Affects 2 files
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts#L271-L275 (this comment)
  • src/renderer/src/components/terminal-pane/keyboard-handlers-korean-prefetch-gate.test.tsx#L65-L75

@nwparker
nwparker merged commit 42fc537 into main Aug 8, 2026
46 checks passed
@nwparker
nwparker deleted the nwparker/gate-korean-prefetch branch August 8, 2026 09:48
nwparker added a commit that referenced this pull request Aug 9, 2026
* Revert "fix(terminal): detach the Korean input-source probe when its setting goes off (#13283)"

This reverts commit 5a84dbb.

* Revert "fix(terminal): stop the Korean gate caching an unknown input source as negative (#13182)"

This reverts commit 4349599.

* Revert "perf(terminal): gate the Korean input-source probe on its setting (#13181)"

This reverts commit 42fc537.

* Revert "feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards (#13104)"

This reverts commit 2400393.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ablyai#13181)

prefetchKoreanInputSource ran under a bare isMac check, so every macOS user
paid for it. Each refresh shells out to `defaults export | plutil | plutil` —
four processes in the main process — and input-source toggle keys pass
force: true, so one Caps Lock press costs two probes. terminalKoreanWonToBackquote
defaults to false.

Threads the setting through KeyboardHandlersDeps and into the effect's
dependencies, so enabling it mid-session still warms the cache before the
first Backquote.

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Revert "fix(terminal): detach the Korean input-source probe when its setting goes off (stablyai#13283)"

This reverts commit 4b8d3e9.

* Revert "fix(terminal): stop the Korean gate caching an unknown input source as negative (stablyai#13182)"

This reverts commit d7061e0.

* Revert "perf(terminal): gate the Korean input-source probe on its setting (stablyai#13181)"

This reverts commit 0712e9a.

* Revert "feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards (stablyai#13104)"

This reverts commit eee48f8.
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