An Android app starts slowly. How do you measure and improve startup?
AndroidSenior
In shortMeasure cold, warm and hot startup on release builds with Macrobenchmark and Play vitals, trace what runs before the first frame with Perfetto, then remove work from Application.onCreate, content providers and the first screen: lazy SDK initialization, background I/O, a lighter first frame, and baseline profiles so startup code is precompiled.
Model answer
Measure: cold startup is what matters most (process created from scratch). Use Macrobenchmark (StartupTimingMetric) on release-like builds and real devices, report time to initial display (automatic) and time to full display (reportFullyDrawn() when real content is shown), and watch Play vitals for slow cold starts (Play flags cold starts over 5 s).
Trace: a Perfetto trace of startup shows bindApplication, Application.onCreate, content provider initialization, activityStart, the first Choreographer#doFrame and any I/O or lock waits on the main thread.
Typical culprits and fixes:
- SDKs initialized eagerly in
Application.onCreateor through their ownContentProviders → initialize lazily or after the first frame; use the App Startup library to control order and disable automatic initializers. - Disk or network on main (databases, large SharedPreferences, config fetches) → move off main, show cached content first.
- Heavy first screen → a lighter first frame, defer non-visible work, avoid inflating hidden UI.
- Interpreted and JIT-compiled code on first run → baseline profiles (and startup profiles for DEX layout) so critical paths are compiled ahead of time; this often cuts cold startup noticeably.
- Dependency injection graphs that create everything eagerly → lazy providers.
Prevent regressions: a startup Macrobenchmark in CI on a fixed device with thresholds, and startup metrics per release in the release checklist.
What they're looking for
Startup types and metrics (TTID, TTFD with reportFullyDrawn), measurement tools, typical culprits, concrete fixes including baseline profiles, and regression prevention.
Common mistakes
- Measuring debug builds.
- Moving work to a background thread that the first screen then waits for.
- Ignoring SDKs that initialize through content providers.
More android questions
- How do you make sure background work in a mobile app stops when the user leaves the screen?Mid-level
- What's the difference between a configuration change and process death on Android, and what survives each?Mid-level
- How would you modularize a large Android app, and how do you keep builds fast?Senior
- How do you store an auth token securely on Android?Mid-level