App Startup: Cold Start From Tap to First Frame

Startup is the first performance number users feel, and most of it is work you chose to do too early.

Part 1 of 5

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.

Why it matters

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.

01Cold, warm, hot start

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.

02Time to initial display

When the first frame draws. The OS reports this one.

03Time to full display

When real content shows. You report this one, and users care about it more.

04Baseline Profiles

Tell Android which code to compile ahead of time, so startup avoids interpreting it.

05Lazy initialisation

Creates a dependency on first use, not at launch.

Part 2 of 5

Question

What exactly you must answer, and what to settle before you start.

2.1Question

Interviewer

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 askAnswer
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.
Part 3 of 5

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.

  1. 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.

  2. 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.

  3. Remove early work

    Move SDKs to first use or after the first frame. Each team must justify anything that runs before the first screen.

  4. 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.

  5. Compile ahead

    Ship Baseline Profiles on Android, and trim dynamic libraries on iOS, which load one by one at launch.

  6. 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

PhaseYou controlTypical fix
Process and runtimeLittleBaseline Profiles, fewer dynamic libraries
App initialisationA lotLazy SDKs, smaller dependency graph
First screenA lotFlatter layouts, no synchronous disk reads
Real contentA lotLocal 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.

FeedCache.ktKotlinCopy
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}
9 linesUTF-8Kotlin
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.

RowUi.ktKotlinCopy
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()
10 linesUTF-8Kotlin
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.

Part 4 of 5

Q&A

What interviewers ask next. Answer out loud, then open.

4.1Interview questions

Why measure p90 on mid-range devices?
Averages on flagship phones look fine while a large share of users wait four seconds.
Should a splash screen hide the delay?
No. It changes nothing measurable and users learn to wait. Reduce the work.
How do you keep 20 teams within budget?
Give each team a share of the budget, show per-module cost in CI, and block merges that exceed it.
Part 5 of 5

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.