Android computing, code optimization

learn from

http://hukai.me/android-performance-compute/

http://hukai.me/android-training-performance-tips/


1. The trace view will be used for analysis to analyze two situations: 1. The execution time is long; 2. The execution time is short but the number of executions is large.

2. Two ideas: 1. Do repeated operations once, such as sorting before binary search, just do it once; 2. Cache

3. Algorithms: Learn to choose the optimal algorithm in different scenarios, and even improve old algorithms and innovate your own algorithms

4. Comprehensive mastery and deep understanding of the collection framework, such as arraylist giving an initial value, why? For example, linkedlist is more suitable for use than arraylist.

5. A new container provided by Android: 1.pair2.sparseArray. . .

6. Avoid unnecessary objects. For example, the automatic boxing of int to Integer should be avoided, and the use of StringBuilder should be avoided.

7. An overlooked point: If an inner class wants to access the private member of the outer class, it is best to set the member to package-public, that is, no modification.


This part of things depends on experience, and cannot be included in an article. There are also memory, startup, rendering and power optimizations worth paying attention to.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324702588&siteId=291194637