fix: resolve high CPU usage and memory leaks at idle (#368)#369
Merged
fix: resolve high CPU usage and memory leaks at idle (#368)#369
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause: A cascading UI re-render loop where every 30-second health monitor ping, every tab switch, and every window focus change triggered unconditional
activeSessionsdictionary writes that invalidated all open windows' views — even when nothing meaningful changed.Changes (16 fixes across 15 files)
Critical — Idle CPU elimination:
updateSession()against no-op writes usingisContentViewEquivalent+ driver identity comparisononStateChangedcallback for routine healthy↔checking health monitor ping cyclesswitchToSessionthrough guardedupdateSession(lastActiveAt-only changes are no-ops)connectionStatusVersionsdictionary so each window observes only its own connection's counterHigh — Correctness & Performance:
fetchTables,fetchColumns,executeSchemaChanges) inqueriesInFlightto prevent health monitor TOCTOU races on shared non-thread-safe C driver handlesactiveCoordinatorsmemory leak by movingregisterForPersistence()frominit()tomarkActivated()DatabaseRowProvider.prefetchRowsDB fetch off MainActor with tracked task and dedup guardMedium — Startup & UI:
Task.detachedfor non-blocking startupbundle.load()off MainActor vianonisolated staticmethodloadConnections()disk I/O inContentView.initwith in-memory lookupWindowLifecycleMonitorto weakNSWindowreferences withpurgeStaleEntries().connectingstatus writes during reconnect attemptsreloadData(forRowIndexes:columnIndexes:)for FK metadata instead of full table reloadDispatchWorkItem[weak self]to nestedDispatchQueue.main.asyncinSQLEditorCoordinatorPerformance impact
With 5 open connections at idle:
updateSessionno-ops skip dictionary writes entirely; each window only observes its own connectionTest plan
Summary by CodeRabbit
Bug Fixes
Performance