Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to improve the startup speed of App

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to improve the App startup speed", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to improve the App startup speed" this article.

1. If you want to do something good, you should sharpen its tools first.

Use Traceview to analyze our startup process.

1.1 introduction to Traceview

Traceview is a performance analysis tool, mainly to analyze the current thread situation, each method execution time and so on. As follows:

Indicator description:

Incl (Inclusive) Cpu Time

The method itself and all submethods it calls take up CPU time.

Excl (Exclusive) Cpu Time

The method itself takes up CPU time.

Incl Real Time

Method (including submethods) from the beginning to the end.

Excl Real Time

The time from the beginning to the end of the method itself.

Call + Recursion Calls/Total

The number of times the method is called + the number of times the method is called recursively.

Cpu Time/Call

One call to the method takes up CPU time.

Real Time/Call

The actual execution time of one call to the method.

In general, we use Real Time/Call sorting to find time-consuming methods

It is necessary to explain CPU Time and Real Time:

Actual execution time of CPU Time method (excluding io wait time)

Time difference between the start and end of the Real Time method (including wait time)

Reference: http://stackoverflow.com/questions/15760447/what-is-the-meaning-of-incl-cpu-time-excl-cpu-time-incl-real-cpu-time-excl-re/17902682#17902682

1.2 Traceview usage

There are two ways to use Traceview:

A, through DDMS:

When you click start, a box will pop up to select trace mode. You can select "Sample based profiling" by default:

Sample based profiling (based on sample analysis)

According to the sampling interval to regularly interrupt the VM to record the method call stack (Call Stack), the overhead is proportional to the sampling frequency.

Trace based profiling (based on full trace data analysis)

Record the entrances and exits of each method, and open the record when each method is executed, no matter how small the method is, so it is very expensive.

B, use the code:

/ / start Debug.startMethodTracing ("GithubApp") where you want to start debugging; / / stop Debug.stopMethodTracing () in the right place

Note: the above method opens trace in the same way as "Trace based profiling" and records the execution of each method. Android 4. 4 and above can call startMethodTracingSampling () to open the trace mode of "Sample based profiling" with code.

2. App startup process analysis

If you want to optimize the App startup process, you must first understand its startup process.

For the specific process, please refer to this translation: Android Application initiates process analysis.

3. App startup mode

Generally speaking, an App startup can be divided into three different states as follows:

Cold start

App has not been started or the App process has been killed, and the App process does not exist in the system. Starting App at this time is a cold start.

The cold start process is the whole process of App startup described in Section 2, which requires creating an App process, loading relevant resources, starting Main Thread, initializing the first screen Activity, and so on.

During this process, the screen displays a blank window (the color is based on the theme) until the first screen Activity is fully started.

The following figure shows the timeline of a cold start:

Hot start

Hot start means that your App process is just in the background, and the system just takes it from the background to the foreground and shows it to the user.

Similar to cold startup, the screen displays a blank window (the color is based on the theme) until the activity rendering is complete.

Warm start

Somewhere between cold start and hot start, it generally occurs in the following two situations:

The user back exits App and then starts it again. The App process may still be running, but activity needs to be rebuilt.

After a user exits App, the system may kill App due to memory reasons, and both the process and activity need to be restarted, but the state saved by the passive kill lock (saved instance state) can be restored in onCreate.

Through the description of the three startup states, we can see that the startup optimization we are going to do is for cold startup. Both hot start and warm start are relatively fast.

4, where are the enemies of App's quick start?

According to the cold start time chart, you can see that for App, there are no other points of the startup timeline that we can control:

OnCreate of Application

Rendering of the first screen Activity

While our current App is easily integrated with many third-party services, we need to check advertising, registration status and other interfaces when starting up. A series of interfaces are done in Application's onCreate or onCreate on the first screen.

This is also recommended in SDK documentation for many third-party platforms.

The above is all the contents of the article "how to improve the startup speed of App". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report