preface

Version: Cocos Creator 3.1

Performance optimization is a common problem faced by front-end game development engineers. For beginners, hearing the word “performance optimization” is often intimidating from the start because they don’t know much about it.

Feather hope to be able to start from zero, try to optimize this matter to everyone to introduce their own understanding, a little enlightenment to the new person, but also welcome the big guy to amend, supplement, after the collection is completed, and then for everyone’s opinions and problems out of a supplementary article.

What is performance tuning?

Performance bottlenecks we commonly encounter are:

  • Space performance bottleneck

    The space performance includes the size of memory, the size of video memory, under normal circumstances, we face the bottleneck of memory performance. When the memory footprint is too large, it often causes the program to crash.

  • Time performance bottleneck

    The intuition is that the game is stalling. Time performance bottlenecks include CPU performance bottlenecks and GPU performance bottlenecks. GPU performance is very strong. In most cases, the time performance bottlenecks we face are often CPU performance bottlenecks.

Performance optimization, in a nutshell, is a process of finding the real cause of a performance bottleneck and choosing a solution based on the cause.

From the perspective of balance, I understand performance optimization as: balance of time, space and game effects after eliminating redundancy.

Steps for performance optimization

1. Performance measurement, only measurable performance is easy to optimize. Identify performance problem situations, benchmark models for performance testing, conduct performance measurement, and set optimization objectives.

2. Analyze the performance and find the performance bottleneck. Determine whether the performance bottleneck is temporal or spatial.

3. Determine the primary and secondary causes of the performance bottleneck. Common causes are classified:

  • CPU performance bottlenecks:
    • drawcall
    • physic
    • logic
    • triangle
  • Memory bottleneck:
    • Texture format Size and format
    • The resource load is not released
    • Object memory leak

4. According to the cause priority, according to the performance measurement results, optimize successively (according to the great Marxist philosophy theory, solve the primary contradiction first, then solve the secondary contradiction), until the optimization goal is reached.

To solve the main reasons, the optimization effect is obvious, and the later optimization effect and time ratio are reduced. Enough is enough.

Performance measuring tool

For games developed with Cocos Creator, there are a number of performance measurement tools available. The game debug panel, Performance for Chorme, and as/ Xcode IDE performance tools all provide debugging information about memory, frame rate, network traffic, and so on.

Feather today mainly introduces the debug information panel of Cocos Creator, as a start of performance optimization learning.

Debugging information panel interpretation

  • Framerate (FPS) frame rate

    FPS Frames Per Second refers to the number of Frames transmitted Per Second, which is generally referred to as the number of animation or video Frames. The more frames per second, the smoother the action will be, but the amount of data processed by the GPU will also surge, potentially causing stutter. Generally, for mobile games, we set the game to run at 60 frames to the full, and when it falls below 30 frames, there is a noticeable lag.

  • Draw call

    The CPU and GPU work in parallel, with a command buffer between them. When the CPU needs to call the GRAPHICAL programming interface, it adds commands to the command buffer. When the GPU completes the last rendering command, it continues to execute the next command from the command buffer. There are many kinds of commands in the command buffer, and drawCall is one of them.

    When the CPU submits a drawcall, it needs to process a lot of things, such as some data, states, commands, etc. Some render lag problem is caused by the GPU rendering speed faster than the drawcall submission speed. It may be that the CPU still calculates the drawcall after the last rendering. Therefore, a high drawcall may cause CPU performance bottlenecks.

  • Frame time(ms)

    Frame Time = 1/ FPS, the time of each Frame. Technically speaking, if our game runs at a full 60 frames, the maximum budget per frame is 16ms (1000ms / 60 frames per second ≈ 16ms).

  • Instance Count: GPU INSTANCING numbers. 10. INSTANCING implies instantiation of geometry:

    The graphics API can render only a limited number of batches per second, and to render a forest (a large number of small objects with small differences) requires instantiation.

    The instantiation goal is to enable an application to minimize the number of state and texture changes and render the same triangle in the same batch multiple times in a single graphical interface call, thus minimizing the CPU time spent on the submitted batch, known as “commit once, render many times.” Great for rendering large quantities of repeated objects.

    This value will increase when combined batch takes effect.

  • Triangle: Number of triangles. In 2D game development, texture maps are rectangles. A rectangle is made up of two triangles, so one texture map takes up two triangles. In 3D games, the model Mesh consists of N small triangles.

  • Game Logic(MS): Game Logic time consuming

  • Physics(MS): Indicates the physical engine time

  • Renderer(MS): Rendering time

  • GFX Texture Mem(M): Texture cache

  • GFX Buffer Mem(M): GFX cache

After understanding the meanings of the above information, we need to analyze whether it is a temporal or spatial performance bottleneck.

  • If the time of each frame is too high, observe physic, Logic, drawcall, and Triangle indicators. If the time of each frame is too high, observe physic, Logic, drawcall, and Triangle indicators.

  • If it is a space performance bottleneck and a memory bottleneck, you can analyze texture memory metrics, the number of nodes, the number of resources loaded, whether useless resources are released, whether there are memory leaks in the code, etc.

    • The texture memory index can be directly seen in the debugging panel information. If the texture cache is too high, it is bound to directly cause high memory, resulting in memory performance bottleneck, crash and other serious problems.

Optimization methods for different metrics (DrawCall, Physics, GFX Texture Men(M), Game Logic(MS)) will be covered in the next article.

summary

Performance optimization not difficult, as long as to learn the main performance index information read the general bearing capacity and the present model, different indexes of commonly used optimization method, learn to the optimization results are verified through the information panel, and can solve most of the optimization of demand, as for more sophisticated optimization, can learn step by step in the process of practice.

More and more

Declare a custom data array in the editor

. Inclusion optimization guide

Irregular 3D terrain walking

3D dressing based on Creator3.0

Fast 3d parabola drawing

Odd-shaped – Irregular button implementation

Did you lose your skills today?

More wonderful welcome to pay attention to wechat public number?