Optimizing App Launch
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
- System InterfaceSeparate in two phases:
- DYLD3Dynamic Linker: loads shared libraries and frameworks
- libSystem Init: initializes app low level components
- 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
- Separate in two phases:
- UIKit init
- This is when the system initializes
UIApplication
andUIApplicationDelegate
- This is when the system initializes
- Application init
- Invokes
UIApplicationDelegate
app lifecycle callbacksUIApplicationWillFinishLaunching
/didFinish
/DidBecomeActive
- (iOS 13 and later) We now get UISceneDelegate UI lifecycle callbacks for each scene:
willConnectToSession:
,sceneWillEnterForeground:
,sceneDidBecomeActive
.
- Invokes
- 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
- this is when the app views are created, their layout is performed, and they’re drawn.
- 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.