Writing

The cost of a cold start

Launch time is the first promise an app makes, and the one performance number every user measures without trying: thumb on the icon, eyes on the screen, a gut feeling in well under a second. In an app that handles money or identity, slow also feels untrustworthy. And cold start rarely stays fixed. The next team adds an eager singleton or a synchronous call on the main thread, and it's slow again. The real job is keeping it fast for years, not hitting a number once.

You pay before main() is called

A surprising share of launch happens before your first line of code: dyld maps and links your binary and every dynamic framework, then runs static initializers and Objective-C +load methods. Each dynamic framework adds real milliseconds on real devices; a dependency-happy app can spend hundreds of milliseconds in a phase no profiler sample will attribute to your code.

Set DYLD_PRINT_STATISTICS=1 on a device build and read what comes back. The offenders tend to repeat across codebases: too many dynamic frameworks where static linking would do, a logging or analytics dependency whose entire runtime value is two functions, and static initializers quietly doing real work, a “constant” that turns out to be a date formatter or a compiled regex built before the app exists to use it.

Measure like you don’t trust yourself

Launch numbers are easy to fool yourself with. The simulator lies, debug builds lie, and the new iPhone in your hand lies about the old one in your user's pocket. The rules I follow: release configuration, real hardware including the oldest supported device, true cold starts (reboot or long idle between runs), and the median of many runs. Never the one demo run that happened to go well.

Two tools help. During development, signposts around each phase of startup let the App Launch template in Instruments show exactly where the time went. In production, MetricKit reports what users actually experience: MXAppLaunchMetric tells you about devices you'll never hold. And to catch regressions before they ship, you can make launch a test:

final class LaunchPerformanceTests: XCTestCase {
    func testColdLaunch() {
        measure(metrics: [XCTApplicationLaunchMetric()]) {
            XCUIApplication().launch()
        }
    }
}

Run it on a real device in CI and fail any pull request that makes launch noticeably worse. Then nobody has to remember to care, because the pipeline remembers for them.

The startup architecture

Keeping launch fast is less about tricks and more about having a clear rule for what launch is. Mine: launch is the path to the first useful screen, and everything not on that path waits. In practice that means startup work is declared in one place instead of scattered around the app. Every subsystem registers a task with a phase, and nothing else is allowed to run early:

enum LaunchPhase {
    case critical      // before first frame: session, root UI state
    case afterFirstFrame   // first idle: caches, sync, push registration
    case idle          // whenever: analytics, cleanup, prefetch
}

StartupScheduler.register(.critical)       { SessionStore.restore() }
StartupScheduler.register(.afterFirstFrame){ SyncEngine.warm() }
StartupScheduler.register(.idle)           { Analytics.flushQueue() }

The scheduler runs critical work right away, runs afterFirstFrame work at the first idle moment after the screen appears, and lets idle work trickle in behind that. The biggest benefit isn't technical. When every startup task is one line in one file, “can this wait?” becomes a question with a visible answer in code review. An analytics SDK that would have quietly sat on the launch path now has to justify itself in public.

Fast launches aren’t achieved. They’re defended, one code review at a time.

What actually moves the needle

  • Dynamic framework consolidation moves the needle most. It’s also invisible to any profiler that starts sampling at main(), which is exactly why it gets skipped.
  • Deferring work by construction beats deferring it by memory. A scheduler turns a one-time win into a permanent property, because nothing new gets to skip the queue without a reviewer noticing.
  • Killing eager singletons pays for itself immediately. Every shared instance that used to initialize on first import either went lazy or was deleted outright.
  • First-screen honesty covers for everything else. Render cached content immediately, then reconcile with the network after; the skeleton-screen-then-spinner ritual is usually a launch-time confession in disguise.

None of this is exciting, and that's the point. Fast launch is the result of many boring decisions, defended for years. The apps that still feel instant five years later aren't the ones that optimized hardest once. They're the ones that never let it slip twice.