The importance of performance optimization for Android programmers, you will understand after reading it

foreword

I believe that we have all used Android phones, and often encountered problems such as phone freezes, app crashes, and unsmooth screens during use; because of this, the user experience is very poor, and we finally choose not to use Android phones . In this regard, many companies have higher and higher quality requirements for Android projects, which force us to realize that performance optimization is very important, and to some extent even exceeds the development of new features.

Why performance optimization is needed

When we develop Android App projects, except for NDK, we use the java language, because the java language has always been based on the language running on the virtual machine JVM. Compared with C++, the efficiency is relatively low. Java needs to occupy a large amount of memory in exchange for execution speed, and the irregular GC mechanism directly leads to the freeze phenomenon of the Android interface.

Compared with Apple's iOS, Android has to face countless different hardware combinations, resolutions, drivers, etc., resulting in uneven app quality.
At this time, we need to use performance optimization to improve the performance of the program, make our application faster, use less CPU resources, and use less memory.

The importance of performance optimization for android programmers

Although Android performance optimization is an old-fashioned topic, with the continuous improvement of the mobile device and application market, there are more and more Android applications. In order to attract users and ensure business success, many android companies hope that their apps are more efficient and faster than others. As a result, the current market requirements for the skills of Android programmers require experience in performance optimization.

Recruitment needs of major manufacturers
Duringinsert image description here
interviews, many companies will use questions related to performance optimization to examine the technical level of interviewers, such as these common questions:

1. How to evaluate the performance of the application?
2. What performance optimization techniques have been used in Android application development?
3. How to use the Android Profiler tool to detect performance problems?
4. How to use LeakCanary to detect memory leaks?
5. How to use the Lint tool to detect potential performance problems?
6. How to avoid using unnecessary memory in the application?
7. How to reduce the startup time of the application?
8. How to reduce the network request time of the application?
9. How to avoid blocking the UI thread?
10. How do you deal with performance issues with large datasets and long lists?

If you were an interviewer, would you be able to answer the questions fluently? I have communicated with many Android programmers, and they feel that only forming a systematic analysis idea is the key to passing the interview. But you need to know that Android performance optimization includes startup speed optimization, layout optimization, memory optimization, power consumption optimization, apk size optimization, etc., and this aspect is a continuous demand, because the compatibility of each model of Android It is not the same, so the problems will be different, and the Android system is constantly being updated. We need to track and troubleshoot performance problems based on user feedback, and then we can take measures against these problems. This is also a problem that Android development engineers need to solve.

After figuring this out, I believe that everyone should have a deeper understanding of performance optimization. The following is the "Android Performance Optimization Learning Manual" I prepared for you . Friends in need can private message the editor to receive it. It can effectively help everyone establish performance optimization. The overall framework, the knowledge in it is very comprehensive, and many advanced knowledge are explained very thoroughly. At the same time, there are actual combat cases to help everyone understand the project environment and improve the actual problem-solving ability. The next performance optimizer is you!

data content

1. Start optimization

A law that exists on the web page is called the 8-second law: It means that when users visit a website, if they wait for more than 8 seconds to open, more than 70% of users will give up waiting.
Similarly, the mobile terminal also has an 8-second law:
if an app takes more than 8 seconds to start or has obvious freezes, 80% of users will quit the app and spit on the programmer. Of course, this is what I fell in love with, but it doesn't mean it doesn't exist. At the very least, it will definitely affect the ratings in the market, which will allow more users to choose competing products in the comparison process.

insert image description here

2. UI layout optimization

In Android, when the system measures, layouts and controls the View, it operates through the temperature history of the View tree. If the height of a View tree is too high, it will seriously affect the speed of measurement, layout and drawing. Google also recommends in its API documentation that the View height should not exceed 10 layers.
3.insert image description here
Caton optimization

  • The layout can be said to be the most important item of the APP. The user perception is very strong. No matter how your code is written, the user does not know it. The user can only see and operate the APP. A more beautiful and reasonable layout and a smoother experience It is a good APP.
  • For example, WeChat, when it is difficult to operate, users will only think that the mobile phone is not working, not WeChat. But for other APPs, users will feel that the APP is not working, not the mobile phone.

​4.insert image description here
Crash optimization

The crash rate is a basic indicator to measure the quality of an application, so how to measure the crash objectively and how to look at the stability related to the crash.

insert image description here

5. Network optimization

With the continuous upgrade of the mobile network, the network transmission of the client has evolved from 3G to Wif and 4G, and there are more and more Wif scenarios. Although the network environment is getting better, it also puts forward higher requirements for network applications. You will find that many large manufacturers attach great importance to network indicators. will result in varying degrees of loss.

insert image description here

6. Optimize Glide loading super large gif

Why optimize glide's gf support? Back to 2 years ago, we needed to support a lot of png or gf images on the page as the background of the event, and the original gr of the operator was limited to a large size (>5mb). There will be memory jitter, APP freeze, and gO frame drop. Although gif compression can be reduced to a small size, the display effect will be greatly reduced. Only glide and Fresco are the only image loading libraries that support gif for loading research. The project already has glide. Then what we need is to optimize.

insert image description here

7. Storage optimization

The main purpose of memory optimization is to improve the efficiency and performance of the application program, and reduce the crash or freeze of the application program due to memory problems. When an application is running, it needs to apply for a part of memory space through the system to store program data, but if this part of memory space is used too much, it will cause the instability of the entire system memory and the operation of other applications will be affected.

Therefore, through the management and optimization of the memory space of the Android application program, the application program can run more smoothly, the response speed and performance of the application program can be improved, and the crash or freeze caused by insufficient memory can be avoided. At the same time, for low-end devices or devices with small memory, memory optimization can also improve the stability and fluency of the device, and improve the user experience of the device.
insert image description here

Finally, I hope that everyone can advance to become a senior Android engineer as soon as possible.

Guess you like

Origin blog.csdn.net/m0_70749039/article/details/130414401