Skip to content

perf: reduce memory usage by ~80-130 MB per connection#232

Merged
datlechin merged 5 commits intomainfrom
perf/memory-audit-fixes
Mar 9, 2026
Merged

perf: reduce memory usage by ~80-130 MB per connection#232
datlechin merged 5 commits intomainfrom
perf/memory-audit-fixes

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

@datlechin datlechin commented Mar 9, 2026

Summary

Implements 8 memory/CPU optimizations identified in the memory audit (see docs/development/MEMORY-AUDIT.md):

  • Eliminate dedicated ping driver (~30–50 MB per connection): Health checks now use the main driver instead of maintaining a separate C-level driver instance
  • Eliminate metadata driver (~30–50 MB per connection): Metadata queries (columns, FKs, row count) multiplex on the main driver via C-level DispatchQueue serialization. No second TCP connection needed.
  • Lazy-load plugin bundles (~20–30 MB at launch): Plugin discovery (Info.plist) happens at startup, but bundle.load() is deferred until the first driver request or settings screen visit
  • Cross-window tab eviction (reclaim ~90 MB per evicted tab): Inactive native window-tabs evict row data after 5s via NSWindow.didResignKeyNotification, re-fetched on focus
  • Remove RowBuffer.sourceQuery (<500 KB per tab): Eliminated duplicate query string; rehydration reads from tab.query directly
  • Zero-copy InMemoryRowProvider (~3–10 MB per tab): Provider now references RowBuffer directly instead of copying rows; sorted views store index permutation instead of reordered row arrays
  • Window-scoped NSWindow.didUpdateNotification (CPU): Each editor's notification handler now early-returns for notifications from other windows — only 1 handler does work per update cycle instead of N

Also clears InMemoryRowProvider cache when RowBuffer is evicted, fixing a bug where eviction freed RowBuffer.rows but the provider still held its own copy.

Files changed

  • ConnectionSession.swift — removed metadataDriver property
  • DatabaseManager.swift — removed ping driver, metadata driver, ensureMetadataDriver, metadataCreationTasks; health checks use main driver
  • PluginManager.swift — split loadAllPlugins into discoverPlugins + loadPendingPlugins
  • DatabaseDriver.swift — trigger loadPendingPlugins() on first driver creation
  • RowProvider.swiftInMemoryRowProvider holds RowBuffer reference + optional sortIndices
  • MainEditorContentView.swiftmakeRowProvider() passes rowBuffer + sort indices
  • MainContentCoordinator.swift — Phase 2 metadata uses main driver; evictInactiveRowData() method
  • MainContentCoordinator+Navigation.swift — removed all 8 metadata driver sync blocks
  • SQLEditorCoordinator.swift — filter notifications by editor's own window
  • QueryTab.swift — removed RowBuffer.sourceQuery
  • ExportDialog.swift, InstalledPluginsView.swift — trigger lazy plugin load on appear

Test plan

  • Connect to MySQL — verify connection works and health monitoring pings succeed
  • Open table tab — verify columns, FKs, and column defaults load correctly (Phase 2 on main driver)
  • Open 3+ table tabs as native window-tabs — switch away, wait >5s, switch back — verify data reloads
  • Switch database — verify tables reload (no metadata driver to keep in sync)
  • Open Settings > Plugins — verify all plugins appear
  • Export dialog — verify all export formats available
  • Verify sorted query results display correctly
  • Profile with Instruments Allocations to measure actual savings vs baseline

- Eliminate dedicated ping driver, use main driver for health checks (~30-50 MB/connection)
- Lazy-load plugin bundles on first use instead of at startup (~20-30 MB saved)
- Evict inactive native window-tab row data after 5s, re-fetch on focus
- Clear InMemoryRowProvider cache when RowBuffer is evicted
- Remove duplicate sourceQuery string from RowBuffer
- Add MEMORY-AUDIT.md with findings and fix tracking
@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 715dea5 into main Mar 9, 2026
2 checks passed
@datlechin datlechin deleted the perf/memory-audit-fixes branch March 9, 2026 13:44
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