Skip to content

perf(launch): defer non-critical services to first activation#1023

Merged
datlechin merged 1 commit intomainfrom
perf/defer-launch-services
May 6, 2026
Merged

perf(launch): defer non-critical services to first activation#1023
datlechin merged 1 commit intomainfrom
perf/defer-launch-services

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

  • Welcome window memory footprint at launch: 60.7 MB → 47.9 MB (-12.8 MB, -21%), peak 65.6 → 54.0 MB
  • Source: WWDC 2019 Optimizing App Launch"Defer anything unrelated to generating the first frame". Apple's Mac App Programming Guide says the same: "Any objects that are not needed at launch time should be loaded later."
  • This PR moves non-critical services out of applicationDidFinishLaunching to either the first applicationDidBecomeActive (one-shot) or the view's first .onAppear, with idempotency guards on each service so re-entry is a no-op

Changes

  • AppDelegate.swift — adds hasRunPostLaunchActivation guard, splits services across two phases
    • Stays in applicationDidFinishLaunching: theme, sync-settings keychain flag, DatabaseManager.startObservingSystemEvents, MemoryPressureAdvisor, PluginManager.loadPlugins (lazy bundle.load() is a separate PR), MCP server (already conditional), QueryHistoryStorage warm (already detached), launch coordinator, notification observers
    • Deferred to first applicationDidBecomeActive: ConnectionStorage.migratePluginSecureFieldsIfNeeded, AnalyticsService.startPeriodicHeartbeat, SyncCoordinator.start, LinkedFolderWatcher.start, LicenseManager.startPeriodicValidation
  • FavoritesTabView.swiftSQLFolderWatcher.start() moved to .onAppear of the Favorites tab; users who never open Favorites never spin up the FSEvents stream
  • SyncCoordinator.swifthasStarted guard so start() is idempotent even if called repeatedly
  • LinkedFolderWatcher.swift / SQLFolderWatcher.swifthasStarted guard cleared on stop() so reload() still works correctly

Test plan

  • Cold launch: Welcome appears, Settings does not (regression check vs fix(windows): prevent Settings from auto-opening on launch #1022)
  • After ~1s, sync runs (Pull starting, Sync completed successfully in logs)
  • Open Favorites sidebar tab: SQL folder watcher starts, linked SQL files appear
  • Add/remove a linked SQL folder: SQLFolderWatcher.shared.reload() still works (stop clears hasStarted, start re-runs)
  • License validation runs in background (no UI block)
  • swiftlint --strict on changed files: 0 violations
  • xcodebuild Release arm64: BUILD SUCCEEDED
  • vmmap before/after: Physical footprint 60.7 MB → 47.9 MB

@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 0d896e0 into main May 6, 2026
2 checks passed
@datlechin datlechin deleted the perf/defer-launch-services branch May 6, 2026 06:50
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