Repository navigation
perf(terminal): gate the Korean input-source probe on its setting - #13181
Conversation
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]>
📝 WalkthroughWalkthroughThe terminal passes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/keyboard-handlers-korean-prefetch-gate.test.tsxsrc/renderer/src/components/terminal-pane/keyboard-handlers.ts
| // 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() | ||
| } |
There was a problem hiding this comment.
🚀 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
* 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.
…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]>
* 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.
Follow-up to #13104, from my review there. Non-blocking then, cheap to fix now.
prefetchKoreanInputSource()ran under a bareisMaccheck, 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 passforce: true, so a single Caps Lock press costs two probes regardless of cooldown.terminalKoreanWonToBackquotedefaults tofalse(src/shared/constants.ts:349).keyboard-handlers.tshas nosettingsin scope, so this threads the flag throughKeyboardHandlersDepsfromTerminalPane.tsx, which already readssettings. 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/*.tsbuildinfocleared first — stale buildinfo has produced false greens here), oxlint clean, terminal-pane 259 files / 2997 tests. Nomax-linesdisable added; the one at the top ofkeyboard-handlers.tsis pre-existing.cc @hyein-cbio — no defect in your change, just moving its cost behind its own switch.
Made with Orca 🐋