M-Swift All articles
AI & Performance

Your App's First 400ms Are a Crime Scene: Triage Launch Time Before You Refactor

M-Swift

You inherit the app. It has a decade of features, a few haunted view controllers, and a launch that feels like it is thinking about whether to open. The team knows it is slow, but a rewrite is not on the table. Good. Treat launch time like an incident, not a philosophy debate. The first 400 milliseconds are where users form an opinion, and you can usually find measurable wins there without touching the architecture.

Start with a baseline, not a theory

Before you blame SwiftUI, the network, or the intern who left in 2023, get numbers. Build in Release, install on the oldest iPhone you still support, and launch cold five times. Write down p50 and p95. If you only track the average, you are hiding the launches that make people complain.

Use the App Launch template in Instruments, Xcode Organizer's launch metrics, and MetricKit's app launch histogram once the build is in the wild. Then add your own os_signpost events around the work you control: process start, first network request, first decoded image, first frame, and the moment the main screen is actually interactive. 'Launched' and 'usable' are not the same thing.

Split the timeline: pre-main versus your code

A launch has two neighborhoods. Pre-main is dyld loading images, resolving symbols, running static initializers, and getting the runtime ready. Your code starts after that, but the line is fuzzy because lazy work becomes eager the moment something touches it.

In Instruments, look at the launch phases and the dynamic linker activity. In the scheme's environment variables, DYLD_PRINT_STATISTICS can give you a rough view during development, but do not treat it as a production metric. The useful question is simpler: how many dynamic frameworks are on the launch path, and which ones earn their keep?

Dynamic linking is a tax you can see

Every embedded framework has a cost before your first line of app code runs. SDKs love to ship as dynamic frameworks. Internal teams love to split modules. Both can be reasonable, and both can add launch overhead when the app is cold.

Make a list of linked frameworks and sort it by 'do we use this in the first 400ms?' Remove dead ones. Merge tiny internal frameworks that exist only for tidiness. Prefer static linking where it does not break extensions, resources, or SDK licensing. Do not blindly convert everything; test each change on a real device. A framework that saves compile time but costs 40ms at launch is a trade, not a victory.

Swift runtime initialization: find the eager stuff

Swift gets blamed for launch cost more often than it deserves, but there are real things to inspect. Look for global variables, singletons, static properties, and Objective-C +load methods that run or get touched during startup. Even lazy globals become eager once something reads them, and launch code loves to read things.

Search for +load, static initializers in Objective-C bridges, and large type registries in third-party SDKs. Check whether crash reporting, analytics, feature flags, or logging are starting during didFinishLaunching. Some of that may be mandatory before first frame. Most of it is not.

Move eager work behind the first frame

The fastest launch work is the work you do not do yet. Analytics configuration, remote config refresh, cache warming, image preloading, noncritical migrations, and SDK handshakes can usually wait until the first screen is visible. The key is not hiding them in a random background queue; it is scheduling them after the user has something to look at.

In UIKit, a one-shot display link or a viewDidAppear handoff can work. In SwiftUI, be careful with .task on the root view because it can start earlier than you think. Use an explicit 'after first frame' gate, then run the deferred work in a structured task. Keep migrations safe and idempotent. Do not move work that protects user data just because it is slow.

Fix in order of measurable cost

Do not spend a week shaving 2ms. Rank changes by expected launch savings and risk. High-value candidates usually include pruning dynamic frameworks, removing +load, deferring SDK startup, lazy-loading heavy caches, and eliminating synchronous disk reads on the launch path. After each change, rerun the same cold-launch test on the same device. If the p95 does not move, you learned something useful: that theory was wrong.

Put a fence around it

Once you have a win, protect it. Set a launch budget for p95 on your oldest supported device. Add signposts to Release builds so field traces tell you where time goes. Collect MetricKit payloads and review launch regressions alongside crash reports. The goal is not a perfect launch. The goal is a launch you can explain, measure, and keep from drifting back into mystery.

All Articles

Related Articles

Where Did the Sprint Go? A One-Week Build-Time Audit for Swift Teams

Where Did the Sprint Go? A One-Week Build-Time Audit for Swift Teams

Paying for Smarts: The Hidden Cost of On-Device AI in Your Next Swift Release

Paying for Smarts: The Hidden Cost of On-Device AI in Your Next Swift Release

Simulator Says Yes, iPhone Says Yikes: Seven Device-Only Swift Performance Tests

Simulator Says Yes, iPhone Says Yikes: Seven Device-Only Swift Performance Tests