1e41f4b71Sopenharmony_ci# Overdraw Debugging 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciDeeply nested layouts of an application can lead to performance issues such as redundant use of CPU, GPU, and other computing resources. For example, in a deeply nested layout, drawing instructions of some components are partially or completely covered by drawing instructions of others during rendering. When an application draws a pixel on the screen multiple times within a single frame of rendering, this is called overdraw. To help you reduce overdraw, the system introduces the overdraw debugging feature. With this feature, you can view the location and level of the component that causes overdraw. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThis topic describes how to use the overdraw debugging feature and how to reduce overdraw. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci## Enabling or Disabling Overdraw Debugging 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciYou can use the shell commands to enable or disable the overdraw debugging feature. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci- Prerequisites: Developer mode is enabled. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci- Enable overdraw debugging. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci ``` 16e41f4b71Sopenharmony_ci param set debug.graphic.overdraw true 17e41f4b71Sopenharmony_ci ``` 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci  20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci- Disable overdraw debugging. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci ``` 24e41f4b71Sopenharmony_ci param set debug.graphic.overdraw false 25e41f4b71Sopenharmony_ci ``` 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci  28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci- Check whether overdraw debugging is enabled. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci The value **true** means that the feature is enabled, and **false** means the opposite. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci ``` 34e41f4b71Sopenharmony_ci param get debug.graphic.overdraw 35e41f4b71Sopenharmony_ci ``` 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci  38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci## Analyzing Overdrawn Components 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ciAfter you enable overdraw debugging and open an application UI, overdrawn pixels are highlighted by boxes with different colors. A deeper color represents a higher level of overdraw. The mapping is as follows: 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci- Original color: no overdraw. 45e41f4b71Sopenharmony_ci- Blue-purple: Overdraw occurs once. 46e41f4b71Sopenharmony_ci- Green: Overdraw occurs twice. 47e41f4b71Sopenharmony_ci- Light red: Overdraw occurs for three times. 48e41f4b71Sopenharmony_ci- Dark red: Overdraw occurs for four times or more. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciThe following is a sample application with redundant background color nesting. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci```ts 54e41f4b71Sopenharmony_ci@Entry 55e41f4b71Sopenharmony_ci@Component 56e41f4b71Sopenharmony_cistruct Index { 57e41f4b71Sopenharmony_ci @State message: string = 'Hello World' 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci build() { 60e41f4b71Sopenharmony_ci Row() { 61e41f4b71Sopenharmony_ci Column() { 62e41f4b71Sopenharmony_ci Column() { 63e41f4b71Sopenharmony_ci Column() { 64e41f4b71Sopenharmony_ci Column() { 65e41f4b71Sopenharmony_ci Column() { 66e41f4b71Sopenharmony_ci Text("Hello World") 67e41f4b71Sopenharmony_ci } 68e41f4b71Sopenharmony_ci .width('80%') 69e41f4b71Sopenharmony_ci .height('80%') 70e41f4b71Sopenharmony_ci .backgroundColor(Color.White) 71e41f4b71Sopenharmony_ci } 72e41f4b71Sopenharmony_ci .width('80%') 73e41f4b71Sopenharmony_ci .height('80%') 74e41f4b71Sopenharmony_ci .backgroundColor(Color.White) 75e41f4b71Sopenharmony_ci } 76e41f4b71Sopenharmony_ci .width('80%') 77e41f4b71Sopenharmony_ci .height('80%') 78e41f4b71Sopenharmony_ci .backgroundColor(Color.White) 79e41f4b71Sopenharmony_ci } 80e41f4b71Sopenharmony_ci .width('80%') 81e41f4b71Sopenharmony_ci .height('80%') 82e41f4b71Sopenharmony_ci .backgroundColor(Color.White) 83e41f4b71Sopenharmony_ci } 84e41f4b71Sopenharmony_ci .width('80%') 85e41f4b71Sopenharmony_ci } 86e41f4b71Sopenharmony_ci .height('80%') 87e41f4b71Sopenharmony_ci } 88e41f4b71Sopenharmony_ci} 89e41f4b71Sopenharmony_ci``` 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ciThe figure above shows the UI when the overdraw debugging feature is enabled. 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ciFrom the **\<Text>** component **Hello World**, the **\<Column>** components from inside to outside are displayed in dark red, light red, green, blue-purple, and original color. This indicates that the background of each **\<Column>** component is rendered multiple times as the nesting depth increases. 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ciThe system UI (such as the status bar and sidebar) is also displayed in a different color. This is a normal phenomenon. 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci## Reducing Overdraw 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ciThe debugging feature helps you find overdraw problems on the application UI. To reduce overdraw, you are advised to use the following methods: 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci- Use the visibility control or the if-else statement to reduce redundant components. 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci- Reduce drawing instructions on components that are completely blocked, such as the background color and component content. 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci- Use the flattened layout to reduce the nesting depth. For example, combine layout components with similar sizes and functions into one component. 108