WWDC Notes

Optimizing App Launch

Show Apple's description.
Slow app launches are frustrating. Learn about the new app launch instrument and discover how to make your app launch fast. Gain insights into what happens during app launch and how to minimize, prioritize, and optimize work at this critical time. Hear tips and tricks from the engineers making iOS apps launch fast.

Launch phases

  1. System InterfaceSeparate in two phases:
    • DYLD3Dynamic Linker: loads shared libraries and frameworks
    • libSystem Init: initializes app low level components
  1. Static Runtime init
    • Separate in two phases:
      • Initializes the language runtime (objc/swift)
      • Expose dedicate initialization API in frameworks.
      • Reduce impact to launch by avoiding +[Class load]
      • Use [Class initialize] to lazily conduct static initialization
  1. UIKit init
    • This is when the system initializes UIApplication and UIApplicationDelegate
  1. Application init
    • Invokes UIApplicationDelegate app lifecycle callbacks UIApplicationWillFinishLaunching / didFinish / DidBecomeActive
    • (iOS 13 and later) We now get UISceneDelegate UI lifecycle callbacks for each scene: willConnectToSession:, sceneWillEnterForeground:, sceneDidBecomeActive.
  1. Initial Frame Render
    • this is when the app views are created, their layout is performed, and they’re drawn. loadView viewDidLoad layoutSubviews
    • tips:
      • reduce the number of views launched at the beginning
      • flat view hierarchies and lazily load views not needed during launch
  1. Extended
    • apps specific logic

How to test our app launch time

We have an instrument entirely dedicated to analyze launch times: this will split the app launch in all the sections seen above and highlight our code that executes during this phase.

The new XCTest Metrics is also a very useful and lightweight way to make sure to not incur in some huge slowdowns during development.

Missing anything? Corrections? Contributions are welcome 😃

Written by

zntfdr

Federico Zanetello

Federico Zanetello is an iOS Engineer with strong passion for Swift, minimalism, and design. When he’s not busy automating things, he can be found writing at fivestars.blog and/or playing with the latest shiny toys.