Skip to content

Performance Optimization Overview ​

1. Why Is Performance Optimization Needed? ​

Compared with native APP applications, the Unity WebGL export form requires developers to pay more attention to performance and experience tuning. There are several reasons:

Minigames are inherently "instant-on," and in the minigame ecosystem players are more sensitive to startup time. Unity WebGL is based on WebAssembly at its core, so its computing power is inferior to native APPs. Unity has not done special trimming for the WebGL platform, so startup is slow. Therefore, compared with native APPs, we need to do further performance optimization for both startup and runtime.

2. Optimization Goals ​

Based on the platform's evaluations across different game types and device models, we provide performance evaluation standards that Unity WebGL minigames can refer to, so developers can tune the game's startup and runtime performance accordingly.

3. Best Practices ​

3.1 Speed Up Game Startup ​

Select only the first scene in the build options CDN must enable Brotli or gzip compression Streamline the objects in the first scene and render as quickly as possible so players can see the game's first frame Reduce initialization and first-frame logic; the first scene's Awake/Start/first Update should not contain heavy logic Reduce the code package size and remove unnecessary plugins Use a code sub-packaging tool to reduce the WebAssembly first-download package size

For more information, please refer to: Improve Unity WebGL game startup speed First-scene startup optimization Use a code sub-packaging tool

3.2 Load Resources on Demand ​

Try to avoid including resources in any Resource package at any level, as that directory will be packaged directly into the first resource package Use AssetsBundle/Addressable for resource loading A single package is best kept under 2MB The number of concurrent resource requests should not exceed 20

For more information, please read: Use Addressable for on-demand resource loading Use AssetBundle for on-demand resource loading Use the pre-download feature

3.3 Resource Handling Recommendations ​

Try to keep texture maxsize under 1024; reduce quality appropriately for the minigame environment Try not to generate Mipmaps for textures Try not to use the readable/writable attribute for textures Font files should be no larger than 4MB before compression

For more information, please read: Resource optimization tools and recommendations

3.4 Reduce Minigame Memory Usage ​

Do not initialize all unused resources Release unused resources Use a texture compression tool for optimization before publishing Force mono for audio resources whenever possible Enable High Performance+ mode on iOS

For more information, please read: iOS High Performance and High Performance+ modes Optimize Unity WebGL memory Texture compression optimization Detailed explanation of Unity WebGL memory principles

3.5 Reduce CPU Consumption ​

Use High Performance mode on iOS Try to use the Android CPU Profiler to profile computation bottlenecks in the minigame real-device environment Discover problems in advance in the Unity environment using the Unity Profiler For games with heavy physics computation, use Fixed Timestep to control the computation frequency Limit the frame rate on low- and mid-end devices to reduce device heating

For more information, please read: iOS High Performance and High Performance+ modes Use the Android CPU Profiler for performance tuning Use the Unity Profiler for performance tuning