Game Development Lesson 12

Unity WeChat game ios performance optimization

iOS High Performance Mode

In the iOS environment, the standard WeChat mini-game WASM operating mode is JIT-free, and games with high computing performance requirements will be subject to relatively large restrictions. Common cases are:

  1. The frame rate of low-end and mid-range devices is low, and the fluency is difficult to meet the online standard

  2. The CPU computing resource consumption is too high, and the device temperature continues to rise after running for a period of time

The mini game environment framework provides a high-performance operating mode, in which the CPU computing power is significantly improved. However, this mode also has stricter memory and code package restrictions, requiring developers to take appropriate measures to achieve the optimum.

performance improvement

CPU consumption

Through a variety of game projects, we get the CPU usage of the actual game project as shown in the figure below:

 

We come to the following conclusions:

  • The CPU of the high-performance mode is significantly lower than that of the normal mode during the long-term execution process. The latter is in high CPU usage for a long time, so it is easy to get hotter and hotter for a long time.

  • In the initial stage of game startup, there is a CPU peak in high-performance mode for WebAssembly compilation optimization

  • After adopting code subcontracting , the high-performance mode can quickly reduce the CPU usage and maintain the normal level

pressure test

Use some cases of Benchmark Demo provided by Unity for evaluation:

  • Instntiate & Destroy

  • Animation & Skinning

  • Physics Cubes

  • AI Agents

The test process is to continuously increase the computational complexity until the frame rate drops to a specific value.

The higher the score, the better the performance of the representative.

The figure above shows the scores of the normal mode and the high-performance mode on the iOS side. It can be seen that the high-performance mode is significantly better than the normal mode in several stress test examples.

After the actual game test, the frame rate of the game will be significantly improved, although it cannot reach the difference of almost an order of magnitude in Benchmark.

How to activate

The high-performance mode for small games on the iOS side is suitable for small games that run too hot due to insufficient running performance in the iOS environment.

  • Developers who need this ability log in to the WeChat public platform  -> homepage capability map module -> click to enter "Production Efficiency Improvement Package" -> click to enable high-performance mode.

  • After the activation is successful, configure the iOSHighPerformance in game.json to true to enter the high-performance mode, and remove this switch to return to the normal mode, so that the two modes can be compared.

High Performance Mode Limitations

memory limit

In high-performance mode, the memory limit for iOS low-end devices (6s/7/8, etc.) The memory limit is 1.4G, so developers must ensure that the peak value of memory does not exceed this value.

It is recommended that developers optimize the memory of Unity WebGL according to the guidelines .

code size limit

In high-performance mode, WASM code will be compiled and optimized, which requires more compilation consumption and memory. If it is not optimized, you can obviously feel that the device is hot at the beginning of the startup (for example, within 1 minute before startup).

When launching online, it is especially recommended to use the optimization methods of WASM code subpackaging + compressed texture + mini game audio replacement + UnityHeap reservation.

QA

  1. How to judge whether the game has turned on the high performance mode?

    • Delete local mini-games (including development version, trial version and official version),

    • Re-enter the mini game and enable debugging, check the vconsole log, pay attention to the "render" field in the "game start" log if it is "h5", then it is high-performance mode

    • The system and basic library requirements are: iOS>=14.0, basic library>=2.23.1, and the proportion of users is about 75%. If this requirement is not met, it will fall back to the normal execution mode.

  2. In high performance mode, does the game itself need to be modified?

    • There is no need to make any adjustments to the business code, and the normal mode and the high-performance mode can be switched seamlessly.

    • In high-performance mode, please do not set cookies on the server, because the game will not be able to read cookies due to cross-domain issues

    • There is no problem with Android downloading resources, and the high-performance mode prompts network problems such as resource download failures. Please refer to the document Network Communication Adaptation for cross-domain issues.

  3. iOS error prompts that gzip/br compression is not enabled

You can check whether the Content-Encoding is gzip or br through WeChat developer tools

If properly compressed, this error can be ignored.

Cause of the problem: The Content-Encoding header cannot be obtained due to cross-domain

Solution: increase the cross-domain header"Access-Control-Expose-Headers": "Content-Length, Content-Encoding",

  1. Resource download promptisTrusted

  2. Mostly due to cross-domain problems, you can use the developer tool to check whether the Response Header of the corresponding resource has a cross-domain header, please refer to the document Network Communication Adaptation about cross-domain problems

  1. Stuck at boot cover and unable to start

    • Open debugging in the upper right corner, restart the mini game, click the Unity logo at the bottom three times to open vconsole

    • If resource access fails, but Android and developer tools can be downloaded, please refer to QA3 about cross-domain issues

    • "Not implemented" and memory problems appear in systems above 15.4. This is a bug of Unity & iOS 15.4. Wechat provides wasm code subcontracting (recommended) or a temporary fix on the official Unity WebGL forum

  2. Some game UIs will flicker

    • It is known that iOS 15.4 occasionally occurs, if the developer encounters it, please provide a reproducible Unity project and contact minigamedevop08

  3. Why does the game start very hot when the high-performance mode is turned on?

    • Please refer to the previous part of this article, JIT compilation optimization will consume a lot of performance if code subpackaging is not used

  4. In the high-performance mode, is it possible to publish and go online without optimizing the memory and WASM code package size?

    • Not recommended. Although the iOS high-performance mode can increase the computing power, it has more stringent requirements for memory and WASM package volume, and requires more energy for optimization. If you do not do any optimization, it is very likely that you will encounter problems such as crashing due to exceeding the memory limit, and severe hotness when starting. When launching online, it is especially recommended to use the optimization methods of WASM code subpackaging + compressed texture + mini game audio replacement + UnityHeap reservation.

  5. How does iOS high performance mode compare with Android performance?

    • In both system environments, WASM executes JIT code. However, due to the large differences in the underlying virtual machines and their continuous iteration, it is difficult to compare horizontally.

    • Continue to study the free cloud server and free virtual host provided by the remote Mitutoyo Cloud to see if you can get one

Guess you like

Origin blog.csdn.net/s178435865/article/details/127779039