A music-streaming app's cold start crept from 1.2 to 3 seconds over a year of releases; how do you find what sits on its critical path, and what do you cut?
answer
- field data first, then a trace
- two finish lines, not one
- what the main thread does before frame one
- office Wi-Fi hides a blocking call
- paint the last known state from disk
basics
~20 sFind the release and device class in field data, trace a cold start on a low-end phone, list everything before the first frame and before playable content, then defer, lazily build or move off the main thread whatever neither needs.
solid answer
~50 sStart in field data: which release moved it, for which start type and device class. Then reproduce cold, on a low-end phone, on a throttled network, and trace the main thread to two finish lines: the **first frame**, and **usable content**, meaning the now-playing bar with the last track and a working play button. List everything before each: SDK set-ups, an object graph built whole, disk reads and deserialisation on the main thread, any network call the screen waits for, such as a blocking config fetch. Keep only what the first screen needs: paint the last known track and playlists from disk instead of waiting for the network, build the rest of the graph lazily, move I/O off the main thread, and defer the SDKs. On one platform a watchdog ends a launch that draws no first frame within its allowance, which is a ceiling for disasters, not a target.
go deeper
Know that a launch has two finish lines, the first frame and usable content, and that network or disk work on the main thread before the first frame is the classic cause of a slow one.
Explain how to classify everything on the path before the first frame (SDKs, object graph, disk, network, first-screen layout) and which fix fits each: defer, build lazily, or move off the main thread.
Demonstrate the diagnosis order: locate the regression in field data by release, start type and device class, reproduce cold on a low-end device, and read an idle-but-late main thread as waiting rather than working.
Address why it crept: no failing signal when work was added. Propose the budget, the registry of start-up work and the review rule that make every addition to launch a visible decision.
## Locate before you trace A slow launch that "crept" over a year rarely has one cause; it has twenty small ones, each added by a team that measured nothing. Field data narrows the search first: 1. **Which releases moved it?** Compare the same percentile release over release; steps point at specific changes, a ramp at accumulation. 2. **Which start type?** A regression only in cold starts points at process-start work; one in all start types points at the first screen. 3. **Which devices?** If only low-end phones regressed, the cause is CPU or disk work that a fast phone absorbs. 4. **Which entry point?** Launches from a notification or a lock-screen control may build a different first screen from launches from the icon. Then reproduce it the way users meet it: **cold, release build, low-end device, realistic network**. A flagship on office Wi-Fi hides exactly what grew. One platform's guidance notes that synchronous networking problems do not appear when testing on a good office connection and become common once the app reaches users on varied networks. ## Two finish lines A launch has two marks: - **First frame**: the app's first drawn screen, replacing the OS's launch placeholder. The OS can time this on both platforms. - **Usable content**: for this app, the now-playing bar showing the resumed track at its position with a working play button, and the playlists listed. Only the app knows when this happens, so it must mark it; on both platforms, work done after the first frame does not count toward the OS's own launch figure, though users still feel it. A fix that moves work from before the first frame to just after it improves the first number and may worsen the second. Track both. ## Audit what runs before the first frame Trace the main thread from process start to the first frame and classify every slice: | Finding | Why it is on the path | Cut | |---|---|---| | Eight SDKs set up eagerly | each asked to be "first" | crash reporting only; the rest after the first frame or on first use | | Object graph built whole | one start-up routine constructs everything | build only what the first screen uses; the rest lazily on first call | | Disk reads on the main thread | playlists and last session loaded synchronously | a small last-session record for the first frame; the rest read off the main thread | | Blocking config fetch | first screen waits for fresh remote values | read cached values; refresh in the background | | Network for content | home screen waits for the server's playlists | paint the last known content from disk, refresh behind it | | Heavy first screen | deep layout, full-size artwork decoded | simpler first layout, placeholder artwork, decode at display size | | One-time migration after an update | runs inline before the first screen | its cost lands on that launch; how to run it belongs to the migration design | A **mostly idle main thread with a late first frame** usually means the thread is waiting on a lock, a disk read, or a reply another thread is fetching, not computing. Look for what the first screen awaits, not for slow code. ## A worked ledger All figures below are this scenario's **assumptions** for the median cold start on a low-end device class, not targets from any platform. | Step | Before (ms) | After (ms) | |---|---|---| | Process creation and library loading | 400 | 400 | | SDK set-up before the first frame | 950 | 80 (crash reporting only) | | Object graph | 400 | 120 (first-screen objects only) | | Disk reads on the main thread | 250 | 30 (small last-session record) | | Config: blocking fetch, then cached read | 600 | 10 | | First screen built and drawn | 400 | 300 | | **First frame** | **3,000** | **940** | Usable content then follows at about 1,240 ms: the playlists finish loading off the main thread and playback is restored, an assumed 300 ms after the first frame. Note what did not move: process creation and library loading. On one platform each extra third-party library adds load time before any app code runs, so dropping an unused SDK, or linking fewer separate libraries, is what shrinks that row. Precompiling the startup path is a further lever for the code that remains, but it cannot speed up waiting. ## The ceiling the OS enforces On one platform a **watchdog** ends an app that has not drawn its first frame within its wall-clock allowance; an example report in that platform's guidance shows about 20 seconds. Two lessons follow: - **It is a ceiling for disasters, not a target.** A launch that survives the watchdog may still be far too slow. - **Its report can mislead.** It records what the main thread was doing when it was ended. Slow work that had already finished, having used most of the allowance, does not appear in that stack. ## Keep it from creeping back The year of creep happened because nothing failed when a team added work to the launch. Close that gap: a field launch budget per start type and device class, checked for every release, and a start-up registry so any new work before the first frame is a reviewed decision.
- The trace shows the main thread mostly idle, yet the first frame is late; what does that suggest?The main thread is waiting, not working: on a lock, a disk read, or a network reply another thread is fetching. One platform's watchdog report makes the same point: low app CPU time over a long wall-clock wait means the app was blocked on a resource. Look for what the first screen awaits, not for slow code.
- Why might the regression not reproduce on the team's test phone?A flagship on office Wi-Fi absorbs exactly what grew: CPU-bound set-up shrinks on fast cores, and a call that blocks on the network returns quickly on a good connection. Reproduce cold, on a low-end device, with a throttled network, using a release build, and confirm against field percentiles for that device class.
- Moving the playlist load after the first frame made the first frame faster but users see an empty home screen longer; what went wrong?The fix optimised one finish line at the cost of the other. The first frame should already show the last known playlists from disk; the network refresh happens behind them. Track first frame and usable content as separate numbers, so a change that shifts work between them is visible.
- Moving start-up work to a background thread always takes it off the critical path.
- The launch is finished once the first frame is drawn.
- Timing launches on the team's newest phone shows whether launch time regressed.
- If the watchdog has not ended the launch, the launch is fast enough.
- A watchdog report's main-thread stack always points at the slow code.