D
PerformanceHard40 XP5 min read

How do you optimize Flutter app startup time?

TL;DR: Reduce startup time: defer heavy initialization (analytics, database) to post-startup, use lazy-singleton service locator, avoid blocking await chains in main(), use deferred components for large features, and target <300ms time-to-first-frame for release builds.

Full Answer

Startup time = time from app launch to first interactive frame. Target: <2s cold start, <500ms warm start. Measured in DevTools Timeline or with firebase_performance app_start metric.

main() Bottlenecks

Each await in main() before runApp() adds latency. Firebase.initializeApp() can take 200-500ms. Move non-critical initialization to post-startup by scheduling it after the first frame.

Lazy Initialization

Register services in GetIt as lazy singletons — they're only created when first accessed, not at app startup. Only initialize what's needed for the first screen.

Code Examples

dartOptimized startup sequence
Output
// Critical path: Firebase init only (~200ms)
// Post-frame: analytics, DB warm-up, remote config
// User sees UI in <500ms instead of waiting for all init
// Lazy singletons: 0ms startup cost

Common Mistakes

  • Awaiting non-critical services in main() before runApp() — delays first frame unnecessarily
  • Initializing all services eagerly in getIt setup — 500ms of object construction before first screen

Interview Tip

💡

The addPostFrameCallback trick — initialize non-critical services after the first frame is rendered — is a key startup optimization. Show you know to separate critical-path work (auth check) from deferred work (analytics).

#startup-time#cold-start#warm-start#deferred-loading#lazy-init