App Startup Time Flashcards
PERFORMANCE › Runtime
- What is the difference between cold, warm, and hot start?
- Cold start creates the process from scratch (Application object, main thread, activity, first inflate/draw). Warm start reuses the process but recreates the activity via onCreate(). Hot start just brings an already-resident activity to the foreground, with no object init or inflation.
- What sequence of steps happens during a cold start before the first frame?
- System launches the app and shows a blank starting window, forks the process, creates the Application object and main thread, runs Application.onCreate (plus any content providers), creates the main activity, inflates and lays out views, performs the first draw, then swaps the blank window for the activity.
- What is the difference between TTID and TTFD?
- TTID (Time To Initial Display) is the time to draw the first frame; the framework reports it automatically via the 'Displayed' logcat line. TTFD (Time To Full Display) extends to when the app is fully usable after async content loads, and the app must signal it by calling reportFullyDrawn().
- Why and when do you call reportFullyDrawn()?
- The system can't know when async-loaded content has finished, so you call reportFullyDrawn() once the UI is fully interactive to record an accurate TTFD. In Compose use ReportDrawn / ReportDrawnWhen / ReportDrawnAfter; for concurrent loads use FullyDrawnReporter's addReporter/removeReporter.
- What problem does the AndroidX App Startup library solve and how?
- Each library shipping its own content provider for init bloats startup, since every provider is instantiated separately with undefined ordering. App Startup replaces them with a single InitializationProvider that runs Initializer<T> components, with create() doing the work and dependencies() declaring ordering.
- How do you make an App Startup initializer lazy / manually initialized?
- Mark its meta-data with tools:node="remove" (or remove the whole provider) so it isn't run automatically, then call AppInitializer.getInstance(context).initializeComponent(MyInitializer::class.java) on demand. Its declared dependencies are initialized automatically too.
- What are baseline profiles and how do they help startup?
- Baseline profiles are lists of hot methods/classes shipped with the app so ART AOT-compiles those paths at install time instead of interpreting or JIT-ing them on first run. They precompile the critical startup and key user journeys, commonly cutting cold start by a meaningful percentage.
- How do you reliably measure startup time in CI, and what does Macrobenchmark give you?
- Use the Macrobenchmark library with StartupTimingMetric, specifying the StartupMode (COLD/WARM/HOT) and iterations on a real device. It produces statistically stable timeToInitialDisplay and timeToFullDisplay distributions, unlike a single noisy logcat 'Displayed' reading.
- What replaced custom splash activities, and what was wrong with the old approach?
- The SplashScreen API (Android 12+, backported via the androidx core-splashscreen compat library, installed via installSplashScreen()) replaces custom splash Activities. A dedicated splash Activity added an extra activity and inflation to the critical path, slowing cold start instead of just theming the existing starting window.