1. To do a good job, you must first sharpen your tools. The Analects of Confucius says: If you want to do your work well, you must first sharpen your tools. If you want to improve the startup speed of the App, we need to first find the points that hold it back. To find these points, we need to use our tools. Many tools have been mentioned in the previous article. Today we will use Traceview to analyze our startup process. 1.1 Introduction to Traceview Traceview is a performance analysis tool, which mainly analyzes the current thread status, the execution time of each method, etc. as follows: Indicator Description: Incl(Inclusive) CPU Time The method itself and all sub-methods it calls occupy CPU time. Excl(Exclusive) CPU Time The method itself takes up CPU time. Incl Real Time The time taken from the start to the end of a method (including submethods). Excl Real Time The time taken for the method itself to start and end. Call + Recursion Calls/Total The number of times the method is called + the number of times the method is called recursively. Cpu Time/Call A method call takes up CPU time once. Real Time/Call The actual execution time of a method call. Generally speaking, we use Real Time/Call sorting to find out the methods that take the most time. It is necessary to explain CPU Time and Real 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 the trace mode. By default, "Sample based profiling" is selected: Sample based profiling The VM is interrupted regularly according to the sampling time interval to record the method call stack. The overhead is proportional to the sampling frequency. Trace based profiling (based on complete trace data analysis) Record the entry and exit of each method, and enable recording when each method is executed, no matter how small the method is, so the overhead is very high. b. Use code:
Note: The above method is equivalent to "Trace based profiling", which records the execution of each method. Android 4.4 and above can call startMethodTracingSampling() to enable "Sample based profiling" trace mode with code. 2. App startup process analysis
3. How to start the app Generally speaking, an App startup can be divided into the following three different states: Cold Start
The following figure shows the timeline of a cold start: Hot Start
Warm start Between cold start and hot start, generally occurs in the following two situations:
Through the description of the three startup states, we can see that the startup optimization we want to do is actually for cold start. Hot start and warm start are relatively fast. 4. What are the enemies of App quick launch? According to the cold start time chart, we can see that for App, the points of the startup timeline that we can control are nothing more than:
Our current apps often integrate a lot of third-party services. When starting up, we need to check advertisements, registration status, and a series of interfaces, which are all done in the onCreate of the Application or the onCreate of the first screen.
5. Conclusion Now that you understand the principles of App startup, know which parts of the App startup process are prone to blocking, and know what tools to use to analyze the execution time of each method, the next step will be easy. |
>>: After working on Android for 5 years, I switched to Java backend!
This article takes games as an example to introdu...
[Abstract] In 2015, Apple's smartphone profit...
[[163186]] A few days ago, I saw a sentence from ...
Nowadays, due to the increasing bidding costs, ma...
On November 2, 2020, NIO just released NIO's ...
The latest Fortune Global 500 list was released, ...
[[136018]] iOS and Android have become the duopol...
Recently, Zhang Chaoyang, founder of Sohu, talked...
After the release of Google Android 5.0, major mo...
Written at the beginning: The success of big bran...
Excerpted from: Inside and Outside the Classroom ...
Samsung officially released this year's flagsh...
The latest review standards for financial industr...
Q: WeChat payment mini program, how does the mini...
Recently, a video circulated online claimed that ...