Sitemap

How Xcode measures app launch time

1 min readJan 21, 2021
Press enter or click to view image in full size

Apple recently added Launch time metric in Xcode organizer and ability to measure launch time in UI tests (XCTApplicationLaunchMetric).

To be able to optimize this metric we should understand, how is it measured. Which code is included and which is not.

Apple documentation says:

Launch Time pane in Xcode shows the amount of milliseconds between the user tapping your icon to launch the app, and the time the system drawing something other than the launch screen.

To understand what is included there I created a simple app where I have AppDelegate, ViewController and View objects, main() function in main.m.

This is what we see in output:

AppDelegate.init
AppDelegate.didFinishLaunchingWithOptions
ViewController.init
View.init
ViewController.viewDidLoad
View.didMoveToWindow
ViewController.viewWillAppear
View.willMoveToWindow
View.didMoveToWindow
AppDelegate.applicationDidBecomeActive
ViewController.viewWillLayoutSubviews
View.layoutSubviews
ViewController.viewDidLayoutSubviews

→ → → → XCTApplicationLaunchMetric stops measurement here

ViewController.viewDidAppear

I created simple UI test and did measurements by adding Thread.sleep to different methods.

func testLaunchPerformance() throws {   measure(metrics: [XCTApplicationLaunchMetric()]) {       XCUIApplication().launch()   }}

It turned out, that everything except the last line (`ViewController.viewDidAppear`) is included into XCTApplicationLaunchMetric.

Good to know, that of course main() is also included into the launch time. But also all Objective-C +(void)load methods for your binary and all linked frameworks.

--

--

No responses yet