Skip to content

perf: reduce memory usage with lazy schema loading and tab eviction#132

Merged
datlechin merged 2 commits intomainfrom
perf/memory-optimizations
Mar 2, 2026
Merged

perf: reduce memory usage with lazy schema loading and tab eviction#132
datlechin merged 2 commits intomainfrom
perf/memory-optimizations

Conversation

@datlechin
Copy link
Owner

Summary

  • Replace bulk fetchAllColumns() with lazy per-table column fetch and LRU cache (max 50 tables) in SQLSchemaProvider — avoids loading all column metadata upfront for large databases
  • Evict inactive tab row data more aggressively: keep at most 2 inactive tabs loaded, include both table and query tabs, exclude tabs with unsaved changes
  • Defer Phase 2 background work (exact COUNT + enum values) by 200ms so Phase 1's QueryResult can be deallocated first, reducing peak memory overlap
  • Share the coordinator's SQLSchemaProvider with SidebarViewModel so sidebar reads cached tables instead of issuing a redundant fetchTables() query
  • Release QueryResult earlier in executeQueryInternal by wrapping extraction in a do {} block before the await MainActor.run suspension point

Test plan

  • 8 tests for lazy schema column loading + LRU eviction (SQLSchemaProviderTests)
  • 7 tests for tab eviction filtering and budget logic (TabEvictionTests)
  • 4 tests for sidebar schema provider cache integration (LiveTableFetcherTests)
  • All 19 tests pass on arm64 and x86_64
  • Build succeeds with 0 lint violations
  • Manual: connect to a database with 50+ tables, verify autocomplete still works
  • Manual: open 5+ tabs, verify switching re-fetches evicted data correctly
  • Manual: verify Phase 2 data (exact row count, enum dropdowns) still appears after brief delay

- Replace bulk fetchAllColumns() with lazy per-table fetch and LRU cache (max 50 tables)
- Evict inactive tab data more aggressively (keep at most 2 loaded)
- Defer Phase 2 background work by 200ms to reduce peak memory overlap
- Share schema provider with sidebar to eliminate redundant DB queries
- Release QueryResult earlier via scoped do{} block before await suspension
@chatgpt-codex-connector
Copy link

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

@datlechin datlechin merged commit afe8d2e into main Mar 2, 2026
1 check passed
@datlechin datlechin deleted the perf/memory-optimizations branch March 2, 2026 04:16
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