Unity performance optimization 1: performance standards, common tools

performance standards

Recommended time:

The performance brought to the player's intuitive experience is the frame rate. In order to achieve the required frame rate, it is necessary to control the time consumption of the CPU. Different types of games have different requirements for the frame rate. The following is the recommended time:

Recommended memory:

The key to avoid game crashes is to control the peak value of PSS memory (actual physical memory Proportional set size). The bulk of PSS memory lies in the resource memory and Mono heap memory in Reserved Total . For projects using Lua, you should also pay attention to Lua memory.

Only when the peak value of PSS memory is controlled below 0.5-0.6 times of the total hardware memory, the risk of flashback is low. For example, for 2G devices, the best PSS memory should be controlled below 1G, and for 3G devices, it should be controlled below 1.5G.

For most projects, the PSS memory is about 200MB-300MB higher than the Reserved Total , so the Reserved Total of 2G equipment should be controlled below 700MB, and that of 3G equipment should be controlled below 1G.

Recommended values ​​for rendering module:

As games have higher and higher requirements for image quality, more and more projects encounter performance bottlenecks that will come from GPU pressure, which will be affected by frame rate, resolution, number of triangles, post-processing , Shader complexity, Overdraw and many other influences, so we need to make some corresponding adjustments for models with different grades, and make more detailed distinctions between models with different gears, so as to achieve higher-end models The better the picture quality, the better the fluency can be guaranteed on low-end models. The following table can be used as a template, and the needs of different game types can be further adjusted. The green value will be better if it can be achieved.

Recommended tools 

Unity Profiler

It is recommended to debug on the real machine, shortcut key A (adapt the data of the current frame to the window), F (select one under Timeline, and quickly focus on the appropriate window)

Profiler Modules can be added or subtracted as needed. Frame records 300 frames of data by default, which can be changed in Preference->Analysis->Profiler. The maximum is 2000, which will increase the consumption of the profile

 Rendering data, a big factor affecting it is the change of camera perspective

Unity Frame Debugger

  • View the rendering process of the current frame. It can list all draw calls and execute each call step by step in order.
  • Check the number of Draw Call calls and indirectly measure the rendering cost of the scene through the number of vertices/indexes.
  • It is also possible to check whether the Batch is normally combined, and check the reason for the non-batch.
  • You can also access the shader properties to get more information about the material and shader , as well as get references to the data used by the object.

 Mali Offline Compiler

Documentation – Arm Developer  official documentation

a. This tool is mainly used to calculate the complexity of Shader, and determine whether the Shader is too complex based on the graded high, medium and low values.

b. It is a command-line tool that provides static analysis of GPU shaders. It can be used primarily to validate shader syntax, identify performance bottlenecks, and measure the performance impact of any changes.

Select the shader, compile it into a file, select the fragment shader or vertex shader code, and use the mali command line to analyze it. 

c. Obtain the FRAGMENT Shader from the Unity editor.


From its report we can get some optimization suggestions:

  • Try not to use if and discard statements
  • Reduce the amount of related calculations and reduce the use of complex functions such as inverse trigonometric functions
  • avoid type conversion
  • Reduce the use of 32-bit high-precision floating point numbers, but it is best to use 332-bit position and depth.
  • Avoid triggering spilling, etc.
     

Xcode FrameDebugger

It only supports metal model machine testing, that is, iPhone. In the Edit Scheme, select the GPU as metal, and you can intercept the information of the corresponding frame. It is similar to the Unity Frame Debugger, but has more complete functions.

After opening, when running on the real machine, through the toolbar below, intercept:

Guess you like

Origin blog.csdn.net/qq_37672438/article/details/131910244