UI rendering optimization

CPU given GPU

Here Insert Picture Description
Control of blue as a controller for controlling the entire CPU to coordinate the operation, including fetching an instruction, the control operation of other modules, and the like.
Orange ALU (Arithmetic Logic Unit) is an arithmetic logic unit, a mathematical and logical operations;
orange Cache DRAM and cache respectively and RAM, store user information.
CPU controller is more complex, a small number ALU. The CPU specializes in a variety of complex Logitech operation, but not good at math, especially floating point calculations.

For example, using hexadecimal color, if you want to change the color, just need to modify the value to hexadecimal. So more of a GPU ALU.

XML is displayed to the screen layout process

Here Insert Picture Description
First, the definition xml control information contains higher wide, then LayoutInflater xml loaded into memory, CPU calculates referred to, generating a bitmap, the graphic CPU to GPU, GPU after referred rasterized display to display.

FPS

12 fps: When the picture frame rate higher than 12 frames per second, the eye will think it is coherent;
24-FPS: sound film is generally 24 frames per second shooting
30 fps: early dynamic video games, usually at about 30 frames per second ;
60 FPS: phone interaction, the need to touch and feedback, needs 60 to reach Caton no effect;

Android system will be sent every 16ms a Vsync signal UI once rendered, if every time successful, we can achieve 60 frames. To achieve 60 frames per second, you need to finish loading xml rendering in 16ms, etc., if not completed within 16ms, then there will be the phenomenon of Caton;

Caton reason

Drawing transition

  1. Solution: Remove unnecessary background color
  2. Flat layout view
  3. Reduce the use of transparent color

UI thread complex operations

  1. Data reduction calculation UI thread

Frequent GC:

  • GC frequent reasons:
  1. Memory Jitter
  2. Instantly generate a large number of objects
  • Minimize or create new objects in the object onDraw in the for loop
  • Try not to use a large number of local variables in a loop

optimize the target

XML into objects to reduce CPU time
GPU reduced redrawn

The concept of transitional draw

GPU once every 16ms painting, graphics transfer from the CPU if there are repeated position will cause the user can only see the top screen, while the bottom of the screen were covered, the bottom part of the draw, although users can not see, but also accounted for computing resources, resulting in unnecessary waste; this case is called transitional draw;
Here Insert Picture Description
open GPU developers debug option in the transition to draw, different colors represent different levels. Red transitional draw the most serious.

Examples of typical transition drawn

Playing cards
Here Insert Picture Description
in front of two cards can only see part of, but lack drawn the entire contents. Cutting through canvas, only the first two drawn to display the contents.

UI optimization solutions

BACKGROUND whether layout;
whether the layout can delete;
Customize View whether the corresponding cut;
layout is enough flattened;
Use Merge remove excess label layer ViewGroup container;
using ViewStub be lazy loading layout;

Published 85 original articles · won praise 1 · views 4325

Guess you like

Origin blog.csdn.net/CSDN_Mew/article/details/103980738