Skip to content

perf: tab restore takes 10+ seconds — native window creation is sequential #762

@datlechin

Description

@datlechin

Problem

Restoring tabs on app launch freezes the app. With 12 tabs: ~10 seconds. With 30 tabs: 24+ seconds, 100% CPU, 800MB RAM.

Root cause

Each tab = one NSWindow (macOS native tab requirement). Each NSWindow creation via SwiftUI's openWindow takes ~800ms:

  • Full SwiftUI view hierarchy creation
  • SessionStateFactory + MainContentCoordinator instantiation
  • SourceEditor + TreeSitterClient initialization
  • Schema loading race condition (12+ parallel loads)
  • databaseDidConnect notification storm (24+ events)

Profiling data

[RESTORE] Disk load: 35ms, 30 tab(s)       ← Fast
[RESTORE] Opened 29 native tabs in 11541ms  ← BOTTLENECK
[RESTORE] Connected in 3163ms
[RESTORE] loadSchemaIfNeeded × 25           ← Redundant
[RESTORE] refreshTables × 12                ← Redundant

Fix direction

Option A: Internal tab bar (recommended)

Build a SwiftUI tab bar inside a single window. All tabs live in one NSWindow, only the active tab's editor is rendered. Native macOS tabs become optional (drag-out). This is how TablePlus, DataGrip, DBeaver, and VS Code work.

Option B: Lazy NSWindow creation

Keep native tabs but create lightweight placeholder NSWindows (AppKit, not SwiftUI) that only show a title. Swap in the full SwiftUI content when the user activates a tab.

Incremental improvements (already identified)

  • Schema load coalescing: add Task-based deduplication on SQLSchemaProvider
  • refreshTables gate: only first coordinator per connection calls refreshTables
  • These reduce redundant work but don't fix the core window creation bottleneck

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions