APP startup time has a great impact on ensuring user stickiness. A long loading time may be directly abandoned by users or bring bad user experience to users. Next, let’s take a look at the relationship between iOS APP startup time and what factors are involved
Cold start and hot start
Cold start
An application starts from scratch without holding any resources. Now, when an iOS app is launched for the first time, when you drop an app into the background and open a lot of other apps, there’s a cold launch.
Warm start
When the user presses the home button, the iOS App is not immediately killed, but retains some resources. Ideally, when the user clicks on the App icon and comes back, the App needs to do very little to return to its original state and continue serving the user. And this kind of continuous survival of the launch of the App, we call it hot launch.
Note that when we manually kill the app and then open it, it is not necessarily a cold launch, because when we look at the loaded resources, we find that the resources are similar in size to the hot launch resources. It is not from scratch, but the interface feels like a cold launch
Different stages of startup
The startup phase can be distinguished by the execution of main, before and after the execution of main
Before the main function executes
We add an environment variable to the application, DYLD_PRINT_STATISTICS, and run the program to print the startup time before main
Dylib loading time: Dylib loading time: The loading time of the dynamic library is optimized at a high speed by Apple system library, so it is necessary to use the system library as much as possible, because the developer’s own dynamic library (framework) will be time-consuming. Apple recommends no more than 6 dynamic libraries, if more than 6, it is recommended to merge the rebase/binding time: Fixed binding internal offset pointer (ASLR) and external symbol time, less optimization possibility, reduced OC class ObjC setup time: Registration of OC class time, optimization possibility is less, reduce OC class, online test data is reduced by 200 classes, can reduce 8ms Initializer time: Load load, grammar intializers list a few of the most time-consuming sections slowest. Optimization is to reduce the amount of code in loads, which are written to memory at compile time, and you can use the initializer method, which is used when the class is first called \
After main is executed
Start main -> The time when the first interface appears. You can use BLStopwatch to monitor the time from the start of main to the first appearance
Optimization ideas after main:
Lazy loading
Enable multithreaded execution initialization
Use code to start the interface and avoid storyboards and XIBs
Here optimization is to optimize according to the specific program business, each situation is different, each person’s level is different, so it can only provide some ideas, specific situation specific analysis