Home>

gpu overdraw

•Open developer selection,"Debug gpu over draw", blue, green, pink, red, over draw deepen in turn

powder Pink is optimized as much as possible,Keep the interface as blue and green as possible

• Red is definitely problematic,can not stand

Analyzing layout levels with hierarchyview

• Remove multiple full screen backgrounds:backgrounds that are not visible in the app,Delete it

•Optimize imageview:For a background that is drawn first,And then draw a picture on it,9-patch format The background stretch part of the background image is set to transparent,The Android 2D rendering engine will optimize the transparent pixels in the 9-patch image.This simple modification can eliminate overdraw on the avatar.

•shorten the view hierarchy•delete unnecessary views, not only can improve the frame rate but also reduce the consumption of memory, while also speeding up the application startup

•textview combination icon,Instead of linearlayout + textview + imageview

•use the Mearge tag

use Flat layout with relativelayout

•especially the listview item layout, must be flat

Don't skimp on the function of android device monitor

•start method profiling•You can observe the method call of each thread,

•can be observedNumber of method invocations, each method execution time

•find out if there is an endless loop,Whether it is time-consuming operation

Using leakcanary to find out of memory

• Be sure to integrate leakcanary during the development phase, and it is very easy to integrate

•Method for timely discovery of activity page memory overflow

•detailed memory overflow method tracking,Easy to locate outliers

Use lint tool to lose weight to apk package

Monitor app performance with oneapm

Use svg instead of images

•Need to cooperate with design

Use xml instead of image

Code specification and compliance

•consistent coding style,Facilitates code maintenance, viewing, and finding problems

Here are some methods for android performance optimization

1. Use hardware acceleration,Add android:hardwareaccelerated="true" to application in androidmanifest.xml. But this needs to be available in android 3.0.

Set cache properties in 2.view.setdrawingcache is true.

3. Optimize your layout.Use the layoutopt command under the tools directory in the Android SDK to see if your layout needs to be optimized.

4. Load views dynamically. Use viewstub to avoid some infrequent views holding references for a long time.

5. Set the background image of the window in the acidity to empty.getwindow (). setbackgrounddrawable (null);Android's default background is not empty.

6. Adopt to optimize the number of layout layers. Adopt to share layouts.

7. Check the size of the heap.

8. Use traceview to view the trace function calls.Targeted optimization.

Use of 9.cursor. However, care should be taken to manage the cursor. Do not open or close the cursor every time. Because opening and closing the cursor is very time consuming.cursor.require is used to refresh the cursor.

10. Use ring buffer (can be implemented using linked list data structure). You can set an upper limit on the length of the linked list,Constantly update the contents of the circular buffer based on changes in gestures.

11. Use surfaceview to refresh the UI in the child thread to avoid gesture processing and drawing in the same UI thread (this is common for common views).

12. Using jni, the time-consuming processing is handled by the c/c++ layer.

13. Some can operate with files,Use file operations whenever possible,File operations are about 10 times faster than database operations.

14. Lazy loading and caching mechanism.The time-consuming operation of accessing the network starts a new thread to do it,Don't do it with ui threads.

15. The message cache reuses the previous message through handler.obtainmessage.


16. File io cache, using an input stream with a cache strategy,bufferedinputstream replaces inputstream, bufferedreader replaces reader, bufferedreader replaces bufferedinputstream. It is applicable to files and network io. E.g:

httpurlconnection con=(httpurlconnection) url.openconnection ();bufferedreader input=newbufferedreader (new inputstreamreader (con.getinputstream ()));
strings;
while ((s=input.readline ())!=null) {

}


17.Layout optimization:use abstract layout tags (include, viewstub, merge), remove unnecessary nesting and view nodes, reduce unnecessary infalte and other adjustable aspects of layout,Incidentally mention layout tuning related tools (hierarchy viewer and lint).

18.Textview property optimization:android:ellipsize="marquee" marquee effect of textview consumes a lot of performance.

19. Using hashmap instead of arraylist reduces time complexity by an order of magnitude.


  • Previous JS to achieve the New Year countdown effect
  • Next Using the template engine in Express