Android performance optimization series 3

1. Performance optimization (I) app startup optimization- https://juejin.im/post/5cc19374e51d456e781f2036 --Optimization scheme in appcation: open the sub thread. There is no handler created in the thread, no operation UI, low asynchronous requirements, lazy loading, and initialization when used, such as network, database, picture library, or some third-party libraries. Use the intentservice onhandleintent() method to initialize some time-consuming operations and optimize flashactivity

2. Performance optimization (II) UI rendering optimization- https://juejin.im/post/5cc2dfc7e51d456e845b4260 How to reduce the time consumption of these two things to meet the needs of reducing the time of converting XML into objects by the CPU after 16ms rendering. 2. GPU reduces the time of repeated drawing.

3. Performance optimization (III) app memory exception- https://juejin.im/post/5cd82a3ee51d456e781f20ce Common tools for analyzing memory: Top / procrank; meinfo; Procstats; DDMS; MAT; Finder - Activity; LeakCanary; LeakInspector; Cause of memory leak: an object with a long life cycle holds a reference to an object with a short life cycle. Generally speaking, it is the object to be recycled. Because the reference problem is not recycled, oom will eventually be generated.

How does Java GC determine memory reclamation? At present, virtual machines basically use reachability analysis algorithm. Why not use reference counting algorithm? Let's talk about how the reference counting method counts the reference counts of all objects, and then compare how the reachability analysis algorithm solves the shortcomings of the reference counting algorithm.

Reference counting algorithm: each object has a reference counter. When the object is referenced once, the counter will increase by one. When the object reference fails once, the counter will decrease by one. When the counter is 0, it means it is garbage and can be recycled by GC. Starting with GC roots as the starting point, the edge of the frontal object in the whole connected graph is a live object. Objects that cannot be reached by GC roots become garbage collected objects and may be recycled by GC at any time. Objects that can be used as GC roots: references used by the running virtual machine stack; Static attribute constant; Object referenced by JNI. If an object has a strong reference, the garbage collector will never recycle it. When the memory space is insufficient, the Java virtual machine would rather throw an oom error to make the program exception crash, and will not solve the problem of insufficient memory by arbitrarily recycling the object with a strong reference. If the strong reference object is no longer used, it needs to be weakened so that the GC can recycle it,

Java reference type: strong reference; Soft reference; Weak reference; Virtual reference. Memory jitter: frequent allocation and recycling of memory (when the allocation speed is greater than the recycling speed) will eventually produce oom.

Invalid Sign

5. Performance optimization (V) long graph optimization, imitating microblog loading long graph mode- https://juejin.im/post/5ce96da06fb9a07ee4633f50 Load long picture control, anti microblog loading mode- https://github.com/yangkun19921001/long_ picture_ view

6. Performance optimization (VI) the boss asked you about the power consumption of our app- https://juejin.im/post/5ce9088f6fb9a07ee4633ef3 Power optimization code- https://github.com/yangkun19921001/battery Battery historian, Google's open source power analysis tool- https://github.com/google/battery-historian Battery historian is running Android 5.0 lollipop (API level 21) And later Android devices to check battery related information and events, but the device is not plugged in.

7. Performance optimization (7) DEX encryption and decryption of APK reinforcement- https://juejin.im/post/5cf3ee295188256aa76bb1e1 Apk reinforcement, DEX encryption, decryption- https://github.com/yangkun19921001/DexEncryptionDecryption Classloader is still very important. Both hot repair and hot loading are based on this principle.

8. Performance optimization (8) dynamic replacement of APK reinforcement- https://juejin.im/post/5cf69d30f265da1b897abd53 Activitythread. Java mian() - > thread. Attach() - > attachapplication() - > SendMessage (h.bind_application) - > process bind after receiving the parameters sent by AMS_ Application - > handlebindapplication() prepare application - > Application app = data. Info. Makeapplication() - > minitialapplication = app here;

Reinforcement process principle: from DEX subcontracting - > encryption - > alignment > signature - > packaging and compression into APK.

9. Performance optimization (IX) exploration of thermal repair principle of APP stability- https://juejin.im/post/5cfce989f265da1b6c5f6991 Pile insertion principle: it is known from the source code that findclass finds the class by traversing dexelements. If we reflect the private array dexelements of dexpathlist, we change the internal order index of the array externally and put the repaired DEX into [0] Is it possible to give priority to the repaired DEX? Obviously, it is true.

10. Performance optimization (10) process maintenance and Realization of APP continuous operation- https://juejin.im/post/5cffe4d4f265da1b695d55d4 Process maintenance scheme- https://github.com/yangkun19921001/KeepAlive Keep alive assembly- https://github.com/fanqieVip/keeplive Monitor the lock screen unlocking event of the mobile phone, and start 1 pixel transparent activity when the screen is locked, Destroy the activity when the user unlocks it, so as to improve the process priority.

Invalid Sign

11. Performance optimization (XI) Proguard compression of code and resources- https://juejin.im/post/5d05dab06fb9a07ea9446e21 What is Proguard? Proguard can be understood as a tool for compressing code and resources. It can provide compression, optimization, obfuscation, and pre verification of Java class files. The compression step is to detect and remove unused classes, fields, methods, and properties. The optimization step is to analyze and optimize the bytecode of the method. The confusing step is to rename the remaining classes, fields, and methods with short, meaningless names. Compression, optimization and obfuscation make the code smaller and more efficient.

12. Performance optimization (XII) APK limit compression- https://juejin.im/post/5d0627f7f265da1bd4247e76 The latest version of wechat 6.5.7 (except picture selector)- https://github.com/GitLqr/LQRWeChat Andresguard is a tool to reduce the size of APK. Its principle is similar to Java Proguard, but only for resources. It will shorten the originally lengthy resource path, such as RES / drawable / wechat to R / D / A.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>