Skip to content

perf: fix idle CPU usage, view cascade re-renders, and editor lag#224

Merged
datlechin merged 9 commits intomainfrom
perf/cpu-and-lag-fixes
Mar 9, 2026
Merged

perf: fix idle CPU usage, view cascade re-renders, and editor lag#224
datlechin merged 9 commits intomainfrom
perf/cpu-and-lag-fixes

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

Addresses user-reported performance issues: high idle CPU (70°C vs 46°C when closed), general lag, and sluggish editor responsiveness.

Deep codebase audit identified 37 issues. This PR fixes 31 across 22 files:

  • NSEvent monitors tied to editor focus — VimKeyInterceptor and InlineSuggestionManager monitors now install/remove on focus/blur instead of running app-wide on every keystroke (P0-1, P0-2)
  • Incremental line counting — VimTextBufferAdapter.lineCount uses delta updates instead of O(n) full recount on every text change; setSelectedRange skips needsDisplay when unchanged (P0-3)
  • Fine-grained observable counters — Split DatabaseManager.sessionVersion into connectionListVersion/connectionStatusVersion to prevent mass view re-renders on unrelated session changes (P0-4)
  • AppState granular tracking — Extract specific AppState properties into local lets so @observable per-property tracking works correctly (P0-5)
  • SQL regex windowing — SQLContextAnalyzer now windows text to last 5K chars before running 20+ clause regexes, matching CompletionEngine's existing pattern (P1-1)
  • 10K char highlight cap — HighlightedSQLTextView, JSONEditorContentView, AIChatCodeBlockView all cap regex matching range per CLAUDE.md rule (P1-2)
  • onChange cascade coalescing — Tab switch onChange uses 16ms Task debounce; merged duplicate handlers (P1-3)
  • @bindable scoped to usage site — Moved from struct-level to local variable in queryTabContent() so @observable per-property tracking isn't defeated (P1-6)
  • O(1) fuzzy matching — Rewrote fuzzyMatch() to use NSString.character(at:) instead of O(n) String.index(after:) (P1-7)
  • DataGrid version tracking — Change reapplication and visual state cache skip work when reloadVersion unchanged (P2-7)
  • VoiceOver state cached — Static property with notification observer instead of per-cell system call (P2-4)
  • SSH tunnel termination handlers — Process terminationHandler for immediate detection; polling interval 30s → 300s fallback (P2-1)
  • onReceive coalescing — TableStructureView merges related notifications with Publishers.Merge + debounce (P2-2)
  • Copy pre-allocation — reserveCapacity + direct append instead of intermediate array + joined() (P2-6)
  • Teardown guards — Fire-and-forget Tasks check isTearingDown after sleep (P2-10)
  • Monitor cleanup consolidation — Idempotent cleanupMonitors() in SQLEditorCoordinator (P2-12)
  • KVO cleanup — UpdaterBridge deinit invalidates observation (P2-11)
  • Column width optimization — Reduced samples for wide tables, char-count estimation instead of CoreText (P1-5)

Test plan

  • Launch app, connect to a database, leave idle for 2+ minutes — verify CPU stays low and temperature doesn't spike
  • Open SQL editor, type queries — verify autocomplete is responsive
  • Paste a large SQL dump (100KB+) into editor — verify no freeze
  • Switch between multiple tabs rapidly — verify no lag
  • Enable Vim mode, navigate with hjkl — verify smooth cursor movement
  • Open query history with large queries — verify highlighting doesn't freeze
  • Connect/disconnect multiple databases — verify sidebar updates without lag
  • Select rows, edit cells, save changes — verify DataGrid responsiveness
  • Copy 10K+ rows — verify no hang
  • Open SSH tunnel connections — verify tunnel health monitoring works

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@datlechin datlechin merged commit 0192d5b into main Mar 9, 2026
2 checks passed
@datlechin datlechin deleted the perf/cpu-and-lag-fixes branch March 9, 2026 08:47
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