IOS startup is divided into cold startup and hot startup:
Cold start refers to the situation that the APP process is not in the operating system, and it is a new start, and the system needs to allocate a new process for it to start
Hot boot is a process in which the user exits the app from the background and restarts to enter the app while the app process is still in the system. It is not a complete boot and does few things
This article refers to the optimization of app is to optimize the startup time of cold start
The startup time can be roughly divided into three parts: main-pre (before main function), main to AppDelegate, and home page rendering time
First, I will talk about the main-pre part. The main work of this part is as follows:
1. Load executable files (i.e..o files)
2. Load the dynamic link library, adjust the Rebase pointer and bind the bind symbol
Register uniqueness checks for classes, categories, and selectors
4. Initialize, including +load
5. Load resource files such as XIB
DYLD_PRINT_STATISTICS = DYLD_PRINT_STATISTICS = DYLD_PRINT_STATISTICS = DYLD_PRINT_STATISTICS = DYLD_PRINT_STATISTICS = DYLD_PRINT_STATISTICS = DYLD_PRINT_STATISTICS
The work done during main_PRE can be optimized as follows:
1. Minimize project files and delete unnecessary or unused source files
2. Reduce the introduction of dynamic libraries as much as possible. If it is really necessary, you can merge multiple dynamic libraries into one
3. Minimize references to the +load method and, if possible, initialize it in initzation so that the method is only executed when the class is used
4. Try to avoid complex XIB files and use storyboard or pure code as recommended by Apple. I recommend pure code as easier to maintain if it is developed by multiple people
Next, let’s talk about what the Main to AppDelegate process does:
The main function delegates didFinish methods to the AppDelegate, so optimizations are generally done in these methods. In this method, we should note the following:
1. Avoid using synchronous operations to initialize some data
Try to avoid doing a lot of I/O in the main thread. If possible, do it in the asynchronous thread, or move it to the home page viewDidApear after it has started
For this time count, you can print a timestamp before didFinish and a timestamp after completion, and the difference between the two timestamps is the execution time
Finally, back to the rendering of the home page, which also needs to avoid the above two points and off-screen rendering, so switching between two screen buffers will also affect the performance of the app
The above are my personal views on optimizing app startup time. If you have any supplements, please give me some suggestions
Source: this article is reproduced by the third party, if there is infringement, please contact xiaobian to delete.