Mobile performance optimization series - startup speed

Mobile performance optimization series - startup speed

Mobile performance has a crucial impact on user experience and retention. As a developer, have you ever been complained about, "Why is this app so big?", "Why does it keep wandering around the app cover and can't click into it?", "It's a bit slow to enter the details?", "I'm using your app on 4G, but my data is a bit insufficient", etc. These problems directly reflect that for an app with a good experience, it is not enough to have only sound functions. The following are some points I have summarized on performance optimization:

Startup speed optimization Fluency optimization Resource optimization Memory optimization
APK size optimization

Let’s talk about startup speed today.

Application startup process

Cold Start

The entire process from clicking the application icon to the UI interface being fully displayed and user-operable.

Features: Most time-consuming, measurement standard

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

Hot Start

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

Features: Less time consuming

Startup process: LifeCycle -> ViewRootImpl

Therefore, the standard for judging the startup speed of an application is the cold start speed, that is, the speed of restarting after killing the application. This item is mainly compared with your competitors.

You should not perform any time-consuming operations in the lifecycle callbacks of Application and Activity. The specific indicator is that the total time you spend in callbacks such as onCreate, onResume, onStart, etc. should not exceed 400ms. Otherwise, the user will feel a noticeable lag after clicking your application icon on the desktop.

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 all system behaviors, and generally we cannot intervene directly.

Subsequent tasks

First, create an Application

Start the main thread

Create MainActivity

Loading Layout

Arrange the screen

First frame drawing

Usually, after the first frame of the interface is drawn, we can consider that the startup is complete.

The following is a flowchart of the startup process from the official documentation, showing how the system process and the application process hand over work. In fact, it is a brief summary of the startup process.

Optimization direction

Our optimization direction is the life cycle of Application and Activity. We cannot intervene in the system tasks during startup. What we can intervene are the performance problems that may occur during the process of creating applications and creating Activities. This process is specifically:

Application's attachBaseContext

Application's onCreate

Activity's onCreate

activity's onStart

Activity onResume

The first frame drawing starts after the activity's onResume method is completed. Therefore, we should try our best to avoid time-consuming operations in these methods. In addition, usually, the data of an application's home page needs to be requested from the network, so when users start the application, they hope to quickly enter the home page and see the home page data, which is also a basis for us to calculate the start-up end time.

Application of U-APM in startup optimization

I used to use Umeng statistics to analyze App DAU, tracking points and other data, and then I discovered U-APM launched by Umeng, so I quickly tried it out.

U-APM is an App stability monitoring, performance monitoring and cloud real machine testing platform launched by Umeng+. Through lightweight integrated access, it can have real-time, reliable and comprehensive application crash, ANR, custom exception capture capabilities, as well as performance capabilities such as freeze and startup analysis. It supports multi-scenario, multi-channel intelligent alarm monitoring, helping developers to efficiently restore the access path and business site of abnormal and stuck users, and shorten troubleshooting time. Let's take a look at what U-APM does in terms of startup analysis.

U-APM supports startup trend analysis, slow start analysis, and startup crash analysis.

Start trend analysis

The startup trend more intuitively displays the average, percentile, interval distribution and other data of the application startup time, as well as the performance decomposition data of 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 source of the problem. This feature displays the percentage of slow start situations and a list of slow start devices. You can customize the classification of slow start in the startup settings. By default, a first startup or cold start that takes more than 3 seconds is considered a slow start, and a hot start that takes more than 1 second is considered a slow start.

The slow start analysis during the cold start phase intuitively shows the slow start ratio and the average slow start time.

Slow start distribution intuitively shows the devices, systems, operators, versions, channels, and regions where slow start is distributed.

Start Crash Analysis

Summarizes crash information that occurs during the startup phase, and supports the classification of crashes during first startup, cold startup, and hot startup. The default startup time limit is 8 seconds, and crashes that exceed the time limit are not classified as startup crashes.

Start Crash Analysis

Summarizes crash information that occurs during the startup phase, and supports the classification of crashes during first startup, cold startup, and hot startup. The default startup time limit is 8 seconds, and crashes that exceed the time limit are not classified as startup crashes.

This is of great help in reducing the application startup time. The official demo has been provided.

Summarize

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

<<:  23 pictures to explain routing protocol: the core technology of computer network

>>:  Why 5G and IoT security is more important than ever

Recommend

Protocol-Oriented Programming and Cocoa (Part 2)

[[403619]] This article is a summary of the autho...

VirMach: $7.2/year KVM-512MB/10GB/1TB/multiple data centers available

VirMach has launched the SUMMER HOSTSALE promotio...

Our company’s “Double 11” flow control plan, come and copy our homework!

[[430197]] Image from Baotu.com If the scenic spo...

European and American telecom operators claim: No one needs 6G

"No one needs 6G. The industry should make 6...

About remote procedure call gRPC

If you have been exposed to distributed systems, ...

TCP

[[381851]] This article is reprinted from the WeC...

Woman connected to WiFi and received a huge bill: Some WiFi is actually charged

Nowadays, surfing the Internet with mobile termin...

It will take time for 5G to achieve a breakthrough from "1 to N"

[[402114]] Recently, the Ministry of Industry and...

Why use MAC address when we have IP address?

IP address and MAC address are both very importan...

SRv6 opens a new IP era

We know that IP data transmission in current bear...