This article is from the entry of “2021 UmENG + Mobile Application Performance Challenge”, author: Ziming; This article describes how the author solved the startup problem with the umeng + U-APM tool.

Mobile performance is critical to user experience and retention. Have you ever been teased as a developer, “Why is this APP so big?” , “how has been APP cover around, don’t go in”, “details into the effect of some CARDS”, “use your APP with 4 g, I don’t have enough flow a little ah” and so on, all these problems directly reflects the fact that a good application experience, the only functioning is not enough, the following is my summary on the performance optimization of points:

  • Start speed optimization
  • Fluency optimization
  • Resource optimization
  • Memory optimization
  • APK volume optimization

Application Startup Process

Cold start

The entire process from clicking on the app icon until the UI is fully displayed and user actionable.

Features: The most time-consuming, measured standard

Start: Click Event -> IPC -> process. start -> ActivityThread -> bindApplication -> LifeCycle -> ViewRootImpl

Warm start

Because it will start from an existing Application process, the Application will not be created and initialized, only the Activity will be recreated and initialized.

Features: Less time consuming

Start process: LifeCycle -> ViewRootImpl

So the standard for judging app launch speed is the speed of cold launch, which is how fast you can restart your app after killing it, compared to your competitors.

You should not do any time-consuming activities in the Application and Activity life cycle callbacks. The total time you spend in the onCreate, onResume, onStart callbacks should not exceed 400ms. Otherwise, after the user clicks on your Application icon on the desktop, You will feel a noticeable lag.

Cold start analysis and optimization direction

Tasks related to cold start

Before cold start

  1. First, it launches the App
  2. Then, load the blank Window
  3. Finally, create the process

It is important to note that these are systematic behaviors, and in general we cannot directly intervene.

Then the task

  1. First, create the Application
  2. Start main thread
  3. Create MainActivity
  4. Loading layout
  5. Decorate the screen
  6. The first frame drawing

Usually after the first frame of the interface is drawn, we can assume that the startup is finished.

The following startup process flow chart from the official documentation shows the transition between system processes and application processes. A brief overview of the actual startup process.

To optimize the direction

Our optimization direction is the Application and Activity life cycle phase, we can not interfere with the system tasks during startup, can interfere with the Application and Activity creation process may occur performance problems. This process is as follows:

  • The Application of attachBaseContext
  • The Application of onCreate
  • The activity’s onCreate
  • The activity of the onStart
  • The activity’s onResume

The activity’s onResume method completes before the first frame is drawn. So time-consuming operations in these methods are something that we want to avoid. In addition, usually, the data of the home page of an application needs to be requested by the network, so users want to enter the home page quickly and see the data of the home page when they start the application, which is also a basis for us to calculate the start end time.

Application of U-APM in startup optimization

I used to use UmENG + statistics to analyze data such as daily activity and buried points of App. I found U-APM launched by Umeng and came to have a try.

U-apm is an App stability monitoring, performance monitoring and cloud real machine testing platform launched by Umeng +. Through lightweight integration can have access to real-time, reliable and comprehensive application of collapse, ANR, custom exception, etc, the ability to capture and caton, start the analysis performance ability, such as support for multiple scenarios, multi-channel intelligent alarm monitoring, to help developers efficient reduction anomaly, caton user access path and the business field, shorten the time required for troubleshooting. Let’s look at what u-APM has done in terms of enabling this capability.

U-apm supports startup trend analysis, slow startup analysis, and startup crash analysis.

Start trend analysis

The startup trend visually displays the average value, fractional value, interval distribution and other data of application startup time, as well as the performance decomposition data during startup. It also analyzes the distribution of startup time after multiple iterations.

Slow start analysis

The slow start analysis helps developers trace the source of the device. This function displays the proportion of slow starts and the list of devices that start slowly. You can customize the classification of slow starts in startup Settings.

The analysis of slow start in the cold start phase directly shows the ratio of slow start and the average time of slow start.

The slow start distribution visually shows the devices, systems, operators, versions, channels, and regions of the slow start distribution.

Startup crash analysis

The crash information during startup can be classified into initial startup, cold startup, and hot startup crashes. The default startup time is 8 seconds. The crashes that exceed the startup time are not classified into startup crashes.

This is a great help in reducing application startup time. Demo has been provided by the official.

Mobile terminal performance optimization is closely linked, and startup time optimization is also an important link. The emergence of U-APM is undoubtedly a benefit for developers, helping developers find problems early and solve them. As for other functions of U-APM, you can log on to the official website to experience them.