Performance Optimization Model

Source: Internet
Author: User

Source: http://hukai.me/android-performance-patterns/#jtss-tsina

0) Render Performance

The most important root cause of performance problems that most users perceive as lag is because of rendering performance. From the designer's point of view, they want the app to have more animation, pictures and other fashion elements to achieve a smooth user experience. But the Android system is likely to be unable to complete those complex interface rendering operations in time. The Android system emits a vsync signal every 16ms, triggering a rendering of the UI, and if each render succeeds, it will be able to achieve the 60fps required for a smooth screen, which means that most of the program's operations must be done within 16ms in order to achieve 60fps.

If one of your operations takes time of 24MS, the system will not be able to render normally when the vsync signal is received, so there is a drop frame phenomenon. Then the user will see the same frame in 32ms.

It is easy for users to perceive that the lag is not smooth when the UI is performing animations or sliding the ListView, because the operation is relatively complex and the phenomenon of dropping frames is prone to lag. There are a number of reasons for dropping frames, perhaps because your layout is too complex to render within 16ms, possibly because there are too many drawing units stacked on your UI, and possibly because the animations have been executed too often. These can cause CPU or GPU overloading.

There are tools that can be used to locate the problem, such as using Hierarchyviewer to find out if the layout in the activity is too complex, or by using the developer options in the phone settings and opening the show GPU overdraw. You can also use TraceView to see how the CPU is performing and to find performance bottlenecks more quickly.

1) Understanding Overdraw

Overdraw (Over-drawn) describes that a pixel on the screen is drawn several times within the same frame. In a multi-layered UI structure, if the invisible UI is also doing the drawing operation, this causes some pixel areas to be drawn multiple times. This wastes a lot of CPU and GPU resources.

When designing for a more ornate visual effect, it is easy to get caught up in the vicious circle of using more and more cascading components to achieve this visual effect. This can easily lead to a lot of performance problems, in order to get the best performance, we have to minimize the occurrence of overdraw situations.

Fortunately, we can open the show GPU overdraw option by using the developer options in the phone settings to see the overdraw situation on the UI.

Blue, light green, light red, crimson represents 4 different levels of overdraw, and our goal is to minimize the overdraw and see more blue areas.

Overdraw sometimes because there are a lot of overlapping parts in your UI layout, or because you don't have to overlap the background. For example, an activity has a background, and then the layout has its own background, and the sub-view has its own background. Simply by removing the necessary background image, this can reduce the number of red overdraw areas and increase the percentage of the blue area. This measure can significantly improve program performance.

2) Understanding VSYNC

To understand how the app is rendered, we have to understand how the mobile hardware works, so we have to understand what VSYNCis.

Before we explain the vsync, we need to know two related concepts:

    • Refresh Rate: Represents the number of times a screen is refreshed in a second, depending on the hardware's fixed parameters, such as 60Hz.
    • Frame rate: Represents the number of frames that the GPU draws operations within one second, such as 30fps,60fps.

The GPU gets the graphics data to render, and the hardware is responsible for rendering the rendered content onto the screen, and they collaborate on both sides.

Unfortunately, the refresh rate and frame rate do not always keep the same rhythm. If there is an inconsistency between the frame rate and the refresh frequency, the phenomenon of tearing is prone to occur (the contents of the upper and lower part of the screen are broken, and the data from different two frames overlap).

Understanding the dual and triple caching mechanisms inside the image rendering, this concept is more complex, please visit here: http://source.android.com/devices/graphics/index.html, and here. article.yeeyan.org/view/37503/304664.

In general, the frame rate exceeds the refresh rate is only an ideal condition, in the case of more than 60fps, the GPU generated frame data will be held to wait for VSync refresh information, so as to keep each refresh has actual new data can be displayed. But we are experiencing more cases where the frame rate is less than the refresh frequency.

In this case, some frames display the same screen content as the previous frame. The bad thing is, the frame rate from more than 60fps suddenly dropped to below 60fps, so there will be LAG,jank,hitching , such as Kaka dropped frame of the situation is not smooth. This is also the reason why users feel bad.

3) Tool:profile GPU Rendering

The performance problem is so troublesome, fortunately we can have tools to debug. Open the developer options in your phone, select the profile GPU Rendering, and select the option on the screen as bars.

After choosing this, we can see the rich GPU drawing information on the phone screen, respectively, about Statusbar,navbar, the GPU rending information of the active program activity area.

As the interface refreshes, the vertical histogram is scrolled to indicate the time required to render each frame, and the higher the histogram, the longer the rendering time is spent. Performance

Performance Optimization Model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.