This article is from the in "161277b47dd90d "2021 Umeng + Mobile Application Performance Challenge" ". This article describes how the author solved the startup problem + U-APM 161277b47dd915 tool.
The performance of the mobile terminal has a crucial impact on user experience and retention. As a developer, have you been complained about like this, "Why is this APP so big?", "How can I keep scrolling around on the APP cover image and I can't click into it", "Enter" The detailed results are somewhat stuck", "I use your APP with 4G, my traffic is not enough" and so on. These problems intuitively reflect that a good experience application is not enough if only the functions are sound. The following is my performance optimization Some points to summarize:
- Startup speed optimization
- Fluency optimization
- Resource optimization
- Memory optimization
- APK size optimization
Let’s talk today about the startup speed
Application startup process
Cold start
From clicking the application icon to the complete display of the UI interface and the user can operate the entire process.
Features: the most time-consuming, measurement standard
Start process: Click Event -> IPC -> Process.start -> ActivityThread -> bindApplication -> LifeCycle -> ViewRootImpl
Hot Start
Because it will be started from the existing application process, the Application will not be created and initialized, only the Activity will be recreated and initialized.
Features: less time-consuming
Startup process: LifeCycle -> ViewRootImpl
Therefore, the criterion for judging the startup speed of an application is the speed of cold startup, that is, the speed of restarting after killing the application. This item is mainly compared with your competing products.
You should not do any time-consuming operations in the life cycle callbacks of Application and Activity. The specific indicator is probably the total time you spend in onCreate, onResume, onStart and other callbacks. It is best not to exceed 400ms, otherwise the user clicks on your application icon on the desktop After that, you will feel a noticeable freeze.
Cold start analysis and optimization direction
Related tasks involved in cold start
Before cold start
- First, the App will be launched
- Then, load a blank Window
- Finally, create the process
It should be noted that these are system behaviors, and under normal circumstances we cannot directly intervene.
Subsequent tasks
- First, create Application
- Start the main thread
- Create MainActivity
- Load layout
- Lay out the screen
- First frame drawing
Usually when the first frame of the interface is drawn, we can think that the startup has ended.
The following is a flowchart of the startup process in the official , which shows how the system process and the application process are handed over. In fact, a brief summary of the start-up process.
Optimization direction
Our optimization direction is this stage of the life cycle of Application and Activity. We cannot intervene in the system tasks during startup. What we can intervene is the performance problems that may occur in the process of creating applications and creating activities. This process is specifically:
- Application's attachBaseContext
- Application's onCreate
- activity's onCreate
- onStart of activity
- onResume of activity
The drawing of the first frame starts after the activity's onResume method is completed. Therefore, we must try our best to avoid the time-consuming operations in these methods.
Moreover, under normal circumstances, the data of an application's homepage needs to be requested by the network, so the user starts the application to quickly enter the homepage and see the homepage data, which is also a basis for us to calculate the start-up end time.
Application of U-APM in startup optimization
U-APM
statistics to analyze App daily activity, burying points and other data, I found that the 061277b47ddee6 launched by Youmeng, and quickly try it out.
U-APM
is the App stability monitoring, performance monitoring and cloud real machine test platform launched by Umeng+. Through lightweight integrated access, you can have real-time, reliable, and comprehensive application crash, ANR, custom exception capture capabilities, and performance capabilities such as freeze and startup analysis. It supports multi-scenario, multi-channel intelligent alarm monitoring, and helps The developer efficiently restores the access path and business site of abnormal and stuck users, shortening the troubleshooting time. U-APM
’s take a look at what 061277b47ddf1d has done to start analyzing this ability.
U-APM
supports startup trend analysis, slow startup analysis, and startup crash analysis.
Start trend analysis
The startup trend is a more intuitive display of the average, quantile, interval distribution and other data of the application startup time, as well as the performance decomposition data during the startup phase. It can also analyze the distribution of startup time after multiple version iterations.
Slow start analysis
Slow start analysis helps developers trace the root cause. This function displays the proportion of slow start and the list of slow start devices. You can customize the division of slow start in the startup settings. By default, the first start/cold start is more than 3 seconds. Slow start, hot start more than 1 second is slow start.
The slow start analysis in the cold start phase visually shows the slow start ratio and the average slow start time.
Slow start distribution, intuitively shows the equipment, system, operator, version, channel, and region of slow start distribution.
Start crash analysis
Summarize the crash information that appears in the startup phase, and support the classification of crashes in the first startup, cold startup, and hot startup states. The default startup time limit is 8 seconds, and the crashes that exceed the time are not divided into startup crashes.
This is a great help in reducing application startup time. The official has provided Demo
Summarize
The mobile terminal performance optimization is closely linked, and the startup time optimization is also a more important link. U-APM
is undoubtedly a welfare for developers, helping developers find and solve problems early. As for U-APM
, you can log official website of 161277b47de0f0. to experience.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。