Testing App Launch Time

Slow App startup times don’t give a great first impression to users of your App. Take too long and Apple may even kill your App before it finishes launching. Use the new metrics in Xcode 11 to test and track your App launch times.

App Launch Time

I wrote about debugging slow app startup times after WWDC 2016 when Apple made some improvements to using the DYLD_PRINT_STATISTICS environment variable. That seems like a long time ago but the basic advice from Apple, repeated at WWDC 2019, remains the same:

  • You have about 400ms to show the first frame of your user interface.
  • After that point your App should be interactive and responsive to the user.
  • Any extended setup work or data load needs to happen in the background to avoid blocking the user interface.

Xcode 11 gained some interesting new testing features that should make following that advice easier. In this post I’m going to concentrate on the new XCTest metrics that allow you to measure and record App launch times as part of your UI testing.

Adding A UI Test To Measure App Launch

If you don’t already use UI Tests create a new UI Test target from the UI Testing bundle template:

Add UI testing bundle target

The default template includes a launch performance test (shown below) but you can also add one manually if you already have UI Tests. I prefer to keep the launch tests in their own test class to make it easier to control the test setup:

import XCTest

class UILaunchTests: XCTestCase {
  func testLaunchPerformance() {
    if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) {
      measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) {

Note that all this test does is launch the application. The key is that it does it within a measure block that collects some metrics while running the block. I’m only collecting the applicationLaunch metric but XCTest now has a list of battery and performance metrics you can collect.

Running The Launch Time Test

When you run the test, Xcode builds and then launches the App five times and reports the average launch time. Ideally, run your performance tests on physical devices rather than the simulator.

Optionally, after you have run the test on a device, set a baseline for the launch time metric:

Set baseline

You’ll get a test failure if the metric is more than 10% worse:

Test failure

Further Details

For more on the new battery and performance metrics introduced with Xcode 11:

For a recap on how to improve App launch time (including the new Instruments template):

For general help on writing UI tests see my quick guide: