GPU overdraw
•Open the developer selection, "Debug GPU overdrawing", blue, green, pink, red, overdrawing deepens in turn
•Pink should be optimized as much as possible, and the interface should be kept blue and green as much as possible.
•There must be a problem with the red and cannot be tolerated
Analyzing layout hierarchyView using HierarchyView
•Delete multiple full-screen backgrounds: Delete the background that is invisible in the application and delete it
• Optimize ImageView: For those whose background is first drawn and then the picture is drawn, the stretched part of the background image in 9-patch format is set to transparent, the Android 2D rendering engine will optimize the transparent pixels in the 9-patch image. This simple modification eliminates overdrawing on the avatar.
•Shorten the View hierarchy structure •Deleting non-necessary Views can not only increase the frame rate but also reduce memory consumption, but also accelerate application startup.
•TextView combination icon, instead of LinearLayout+TextView+ImageView
•Use the catch tag
• Flat layout using RelativeLayout
• Especially the layout of ListView item must be flattened
Don't be stingy about discovering the features of Android Device Monitor
•Start Method Profiling •You can observe the method call status of each thread.
• You can observe the number of times the method is called and the time of each method execution
• Find whether there is a dead loop or whether it is a time-consuming operation
Discover memory overflow using LeakCanary
•LeakCanary must be integrated during the development stage, and it is very easy to integrate
• Methods to detect memory overflow on Activity page in time
•Detailed memory overflow method tracking to facilitate locating exception points
Use lint tool to lose weight for APK package
Monitor App Performance with OneAPM
Use SVG instead of image
• Need to cooperate with the design
Use xml instead of image
Code specifications are formulated and adhered to
• Consistent code style is conducive to code maintenance, viewing and discovering problems
Below I will share with you some methods for optimizing Android performance
1. Use hardware acceleration and add android:hardwareAccelerated="true" in application. However, this needs to be used in android 3.0.
Set the cache property in SetDrawingCache to true.
3. Optimize your layout. Check whether your layout needs to be optimized through the layoutopt command in the tools directory in Android SDK.
4. Dynamically load View. Use ViewStub to avoid some infrequent views holding references for a long time.
5. Set the background image of Window in Activity to empty. getWindow().setBackgroundDrawable(null); is the default background of Android empty?
6. Use optimization of the number of layout layers. Adopt to share layout.
7. Check the size of the Heap.
8. Use TraceView to view tracking function calls. Targeted optimization.
Use of However, be careful to manage cursors well and do not turn them on and off every time. Because opening and closing Cursor is very time-consuming. Used to refresh cursor.
10. Use a ring-shaped buffer (can be implemented using a linked list data structure). You can set an upper limit of the length of a linked list to continuously update the content of the ring buffer according to the changes in the gesture.
11. Use SurfaceView to refresh the UI in the child thread, avoiding gesture processing and drawing on the same UI thread (the normal View does this).
12. Use JNI to place time-consuming processing in the c/c++ layer for processing.
13. For some people who can use file operations, try to use file operations. The file operation speed is about 10 times faster than the database operation.
14. Lazy loading and caching mechanisms. Time-consuming operation of accessing the network starts a new thread to do it, instead of UI threads to do it.
15. Message cache passes the previous message.
16. File IO cache, using input streams with cache policies, BufferedInputStream replaces InputStream, BufferedReader replaces Reader, and BufferedReader replaces BufferedInputStream. It is applicable to both file and network IO. For example:
HttpURLConnection con=(HttpURLConnection)();BufferedReader input =newBufferedReader(new InputStreamReader(()));
Strings;
while((s = ()) != null) {
}
Optimization: Use abstract layout labels (including, viewstub, merge), remove unnecessary nesting and view nodes, reduce unnecessary infalte and other tunable advantages in Layout, and mention layout tuning related tools (hierarchy viewer and lint).
Property optimization: TextView's android:ellipsize="marquee" marquee effect is extremely performance-consuming.
19. Use hashMap instead of arrayList to reduce the time complexity by an order of magnitude.