Android system performance optimization issues and display principles

Speaking of the Android system phone, most people's impression is that they have become a bit stuck for a while. Some programs crashed inexplicably during the operation. When they opened the system folder, they found a lot of files and then used the phone. Butler app constantly cleans and optimizes before it feels a slight increase in operating speed. Even if the mobile phone scores far ahead of scores in various performance running software, it still feels no matter how much memory space is far from enough. I believe that every user who uses an Android system has had similar experience. Indeed, the Android system is not as fluent as the IOS system. Why, obviously, when looking at the hardware configuration of the mobile phone, Android devices will not lose out on IOS devices, even Stronger than it, the key is software.

Android system performance optimization issues and display principles

The reasons for this phenomenon are many, simple list of points as follows:

• In fact, in recent years, as the Android version continues to iterate, the Android system provided by Google has become more and more fluid, and the latest released version is Android 8.0 Oreo. However, Android phones used by most users in China are customized versions by major manufacturers. They are often not the latest native system kernels. Most of them may still remain on Android 5.0 systems, and even Android 6.0 or more are still small. , updates have delays.

• Since the source code of the Android system is open, everyone can modify the source code as long as they comply with the corresponding agreement. Then all domestic manufacturers will transform their Android-based source code into their own externally released systems, such as the Miui system we are familiar with. Huawei mobile phone EMUI system, Oppo mobile phone ColorOS system, etc. Because each manufacturer has modified the Android native system source code, there will be a problem in this area. That is the famous Android fragmentation problem. The essence is that different Android systems have different application compatibility and cannot achieve consistency.

• Due to various Android fragmentation and compatibility issues, Android developers need to adapt different systems when developing applications. At the same time, the development level of each Android developer is uneven, and the written application performance is also There are different types of problems, leading to different user experience in the use of the user experience, then some problems will be converted to Android system problems, and then affect the evaluation of Android phones.

Performance optimization

The point that we want to talk about today is the optimization of Android APP performance. That is, what should we pay attention to when developing an application? How can we better improve the user experience? A good application, in addition to having attractive features and interactions, should also have high requirements on performance. Instant applications are very distinctive. In the early stages of the product, some users may be attracted, but if the user experience is not good, Will give the product a bad reputation.

How should a good application be defined? There are three main areas:
• Business/functions • Logic-based interactions • Excellent performance

As we all know, the Android system as a mobile device-based operating system, hardware configuration is a certain limit, although the configuration is now more and more advanced, but still can not be compared with the PC, the use of the CPU and memory is unreasonable or resource-consuming For a long time, you will encounter stability problems caused by insufficient memory and stalled problems caused by too much CPU consumption.

When faced with the problem, everyone thinks about contacting the user and checking the log. However, they do not know the feedback on the performance issues. The reason is very hard to find. The logs are mostly useless. Why? Because performance issues are mostly non-essential issues, it is difficult to reposition the problem, and there is no critical log, of course, the reason cannot be found. These problems have a great impact on user experience and function usage, so it is important to understand some of the performance optimization solutions and optimize our applications in actual projects to improve the user experience.

Four aspects

The performance issues of the user experience can be summarized in four categories:
• Smooth • Stable • Power-saving, provincial flow • Small installation package

What are the main reasons for the performance problems? The reasons are the same and different, but in the final analysis, they are nothing more than memory usage, code efficiency, appropriate policy logic, code quality, and the size of the installation package. :

Android system performance optimization issues and display principles


As can be seen from the figure, creating a high-quality application should be targeted in four directions: fast, steady, provincial, and small.

Fast: Avoids the use of Caton when it is used, has a fast response, reduces the user's waiting time, and meets user expectations.

Stability: Reduce the crash rate and ANR rate, and do not crash and become unresponsive during user use.

Province: saves flow and power consumption, reduces user cost, and avoids hot phones.

Small: Small installation packages can reduce users' installation costs.

To achieve these four goals, the specific implementation is in the right-hand side of the problem: Caton, unreasonable memory usage, poor code quality, code mess, and excessive installation packages. These problems are also the most encountered in the development process. Problems, while realizing business needs, also need to take this into account, spend more time thinking about, how to avoid optimization after the completion of the function, otherwise the cost of maintenance after the realization of such functions will increase.

Catton optimization

Android applications are slow to start up, and they often get stuck during use. This affects the user experience and should be avoided as much as possible. There are many scenes of Caton, which can be divided into four categories according to the scene: UI drawing, application start, page jump, event response, as shown in the figure:

Android system performance optimization issues and display principles

The root causes of these four kinds of tricks can be divided into two categories:

• Interface drawing.
The main reason is that the level of drawing is deep, the page is complex, and the refresh is unreasonable. Due to these reasons, the scenes of Caton appear more in the UI and the initial interface after startup and jump to the page drawing.

• data processing.
The reason for this kind of stalling is that the amount of data processing is too large and it is generally divided into three situations:
One is that the data is processing the UI thread.
The second reason is that the data processing consumes high CPU, resulting in the main thread not getting the time slice.
The third reason is that the increase in memory causes the GC to be frequent, which causes a stall.
There are many reasons for Caton, but in any case, the cause and the scene are ultimately displayed on the screen of the device to reach the user. In the final analysis, there is a problem with the display. Therefore, to solve Caton, you must first understand the display of the Android system. principle.

Android system display principle

Android display process can be simply summarized as: Android application to measure, layout, after painting the surface of the cached data, through the SurfaceFlinger to render the data to the display screen, refresh the data through Android's refresh mechanism. In other words, the application layer is responsible for drawing, the system layer is responsible for rendering, and the data that the application layer needs to draw is passed to the system layer service through the inter-process communication. The system layer service updates the data to the screen through the refresh mechanism.

We all know that there are three core steps in every View drawing for Android: Measure, Layout, and Draw. The concrete implementation is performed from the performTraversals() method of the ViewRooTImp class. Both Measure and Layout recursively obtain the size and position of the View, and take the depth as the priority. It can be seen that the deeper the level, the more elements, and the time-consuming. The longer it will be.

The actual rendering of the data to be displayed on the screen is achieved through the SurfaceFlinger service in the system level process. What does the SurfaceFlinger service mainly do? as follows:
• In response to a client event, create a Layer to establish a connection with the client's Surface.
• Receive client data and attributes, modify Layer properties such as size, color, transparency, etc.
• Refresh the created Layer content to the screen.
• Maintain the sequence of Layers and make clipping calculations for the final output of the Layer.

Since it is two different processes, then it is definitely a cross-process communication mechanism to implement data transfer. In the Android display system, Android's anonymous shared memory is used: SharedClient. A SharedClient is created between each application and the SurfaceFlinger. , and then in each SharedClient, up to 31 SharedBufferStacks can be created. Each Surface corresponds to a SharedBufferStack, which is a Window.

One SharedClient corresponds to one Android application, while one Android application may contain multiple windows, Surface. That is to say SharedClient contains a collection of SharedBufferStack, which uses double-buffering and triple-buffering techniques in the display refresh mechanism. Finally summarized to show the overall process is divided into three modules: the application layer is drawn to the buffer, SurfaceFlinger renders the buffer data to the screen, because it is a different process, so use Android's anonymous shared memory SharedClient cache to display the data to achieve the purpose .

In addition, we also need a noun: FPS. FPS indicates the number of frames delivered per second. Ideally, 60 FPS will not feel the card, which means that each drawing time should be within 16 ms. However, Android systems may not be able to complete complex page rendering operations in time. The Android system sends a VSYNC signal every 16ms to trigger the rendering of the UI. If the rendering is successful each time, it can achieve the 60FPS required for smooth images. If an operation takes 24ms, the system cannot perform normal rendering when receiving the VSYNC signal. This causes frame dropping. Then the user will see the same frame within 32ms. This phenomenon is more common when performing animations or sliding lists. It may also be that your layout is too complex, stacking too many rendering units, and you cannot complete the rendering in 16ms. Eventually causing refresh is not timely.

Catton Root Cause

According to the principle of Android system display, you can see that the root cause of the impact of the drawing are the following two aspects:

• Drawing tasks are too heavy, drawing a frame takes too long.
• The main thread is too busy. The data is not ready to drop frames based on the VSYNC signal passed from the system.

Middle-low Level Lighting Sky Curtain

Middle-Low Level Lighting Sky Curtain,Ultra Transparency Display,Digital Signage Video Display,High Brightness Led Outdoor Lighting

Kindwin Technology (H.K.) Limited , https://www.ktl-led.com