Launch time performance optimization

Time for a small post about launch time performance optimization. I did some research in improving the launch time of my current app.
I started creating a main.swift file, removed @UIApplicationMain from my AppDelegate and added this line to my main.swift:

let StartTime = CFAbsoluteTimeGetCurrent()

Resulting in this complete file:

//  main.swift
//  Created by Antoine van der Lee on 23/02/16.
//  Copyright © 2016 Triple. All rights reserved.

import Foundation
import UIKit

let StartTime = CFAbsoluteTimeGetCurrent()

UIApplicationMain(Process.argc, Process.unsafeArgv, NSStringFromClass(BRApplication), NSStringFromClass(AppDelegate))

In my AppDelegate I’ve added an label for measurement:

    func applicationDidBecomeActive(application: UIApplication) {        
        if launchTimeLabel == nil {
            launchTimeLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
            launchTimeLabel?.backgroundColor = UIColor.redColor()
            launchTimeLabel?.text = String(format: "Launched in %f sec", startupTime!)

Launch time performance improvement results

It resulted in the following performance numbers:

  • Start:
    0,431786667 sec
  • Removed global vars:
    0,391625667 sec
  • Simplified startup storyboard. Created a storyboard containing one VC, which performs a segue directly in the viewDidLoad, referencing the main.storyboard:
    0,295540667 sec
  • Measured a release build:
    0,317792333 sec
  • Changed Swift optimization level to Whole module optimization and enabled linktime optimization:
    0,256407667 sec

At the moment, the project is quite small. I’ll start a new measurement just before release, to see what the new numbers are.

Follow on Feedly