Basics
The whole idea first, then the terms the rest of this page uses.
1.1Whole idea
A cold start runs in order: the OS creates the process, the runtime loads code, your app initialises, the first screen lays out, and data arrives. Users see nothing until the end. Almost all the time you control sits in app initialisation and the first screen, so the job is to do less, later.
Startup is the first performance number users feel, and most of it is work you chose to do too early.
1.2Key concepts
One idea per card, in plain words.
Cold creates the process from nothing. Warm reuses the process but rebuilds the screen. Hot only brings it forward. Measure cold; it is the worst case.
When the first frame draws. The OS reports this one.
When real content shows. You report this one, and users care about it more.
Tell Android which code to compile ahead of time, so startup avoids interpreting it.
Creates a dependency on first use, not at launch.
Question
What exactly you must answer, and what to settle before you start.
2.1Question
Cold start on mid-range Android has crept from 1.8 s to 4.1 s over a year, across 20 teams. Find out why, fix it, and stop it coming back.
2.2Clarify first
Each answer removes a guess.
| You ask | Answer |
|---|---|
| Which devices and which percentile? | Mid-range Android at p90. Flagship averages hide the problem. |
| What counts as done? | First real content on screen, not the first frame. |
| Who owns startup? | Nobody, which is part of why it regressed. |
Detailed answer
How it works, and how to build or explain it.
3.1Step by step
The mechanism, in the order you would explain it.
- Measure in the field
Report time to initial and full display by device class and app version. Lab numbers alone miss real devices and full caches.
- Trace one slow start
Record a system trace on a slow phone, then sort the main thread by time. A few SDKs and a large dependency graph usually lead the list.
- Remove early work
Move SDKs to first use or after the first frame. Each team must justify anything that runs before the first screen.
- Show local data first
Render from SQLite straight away and refresh behind it. The screen no longer waits on the network, which is the same local-truth design as the sync engine.
- Compile ahead
Ship Baseline Profiles on Android, and trim dynamic libraries on iOS, which load one by one at launch.
- Guard the budget
Fail CI when a macrobenchmark exceeds the budget, and gate staged rollouts on field startup. Without a gate, the next feature undoes the work.
3.2Where the time goes
| Phase | You control | Typical fix |
|---|---|---|
| Process and runtime | Little | Baseline Profiles, fewer dynamic libraries |
| App initialisation | A lot | Lazy SDKs, smaller dependency graph |
| First screen | A lot | Flatter layouts, no synchronous disk reads |
| Real content | A lot | Local data first, then refresh |
3.3Code
A working implementation, then what each part does and why.
A startup budget that fails the build
Every team adds a little to startup. Only an automatic check stops it creeping up.
1data class Phase(val name: String, val ms: Long)2 3/** Fails CI, and names the phases to look at first. */4class StartupBudget(private val totalMs: Long) {5 fun check(phases: List<Phase>): List<String> {6 if (phases.sumOf { it.ms } <= totalMs) return emptyList()7 return phases.sortedByDescending { it.ms }.take(2).map { "${it.name} took ${it.ms} ms" }8 }9}phases.sumOf { it.ms } <= totalMs- Within budget: nothing to report.
sortedByDescending { it.ms }.take(2)- When over budget, it names the two slowest phases, so the failure tells you where to look.
Compiled and tested by npm run test:mobile.
A screen as one mapping
The whole list is a transformation of one database query. That's why the screen needs no sync logic.
1data class JobRow(val id: String, val ui: RowUi)2data class ListSummary(val rows: List<JobRow>, val ticks: Int, val needsReview: Int)3 4/** The whole screen is one mapping over the database query. It never mentions the network. */5fun jobList(db: LocalDb): Flow<ListSummary> = db.jobs6 .map { jobs ->7 val rows = jobs.values.sortedBy { it.id }.map { JobRow(it.id, rowUi(it)) }8 ListSummary(rows, rows.count { it.ui is RowUi.Synced }, rows.count { it.ui is RowUi.Conflict })9 }10 .distinctUntilChanged()db.jobs.map { ... }- Each commit produces one new screen state, whoever made the change.
distinctUntilChanged()- If a sync changed nothing visible, nothing redraws.
val ticks: Int- The eleven green ticks and one amber badge are simply counts of this list.
Compiled and tested by npm run test:mobile.
Q&A
What interviewers ask next. Answer out loud, then open.
4.1Interview questions
Why measure p90 on mid-range devices?
Should a splash screen hide the delay?
How do you keep 20 teams within budget?
Extra depth
Edge cases, counterpoints and what to read next.
5.1Edge cases and counterpoints
Includes the strongest argument against this approach.
Show detailsHide details
- Start-time regressions from data
- A growing local database can slow the first query. Test with a million rows, not a clean install.
- Process death
- Android restores your app after killing it, so saved state must load fast too.
- Counterpoint
- Some early work pays for itself, such as crash reporting. Keep it, and account for it in the budget.