Skip to content

Improve Game Startup Speed ​

1. Why Do Startup Optimization ​

1.1 Startup Differences Between Minigames and Mobile APPs ​

Minigames have the "instant-on" characteristic, while mobile APPs often require a relatively long download time. Minigame players are more sensitive to startup time, so an overly long startup time will cause significant user churn.

1.2 Optimization Goals and Standards ​

Currently ordinary minigames generally have a startup time of 7~10s, whereas an unoptimized Unity WebGL game startup is 2-3 times or more that time. We recommend developers treat startup optimization as the most important task before going live.

2. Analyzing Minigame Startup Speed ​

2.1. Viewing Startup Time ​

By changing hideTimeLogModal to false in unity-namespace.js to display the timelog, developers can see the minigame's current first-screen startup time.

To understand the meaning of each stage, we must understand the startup flow.

Minigame startup is mainly affected by three parts:

  • First-package resource download
  • WASM code download and compilation
  • Engine initialization and the developer's first-frame logic

It is recommended to keep the first-screen startup time within 5~10s or even shorter.

2.2 Time by Stage ​

2.2.1 First Resource Package Download and Size ​

The first-package resources (the data file under the webgl/Build directory) mainly consist of:

  • unity default resources file: engine default resources, such as the Arial font, default meshes, textures, etc.
  • il2cppmetadata: information such as classes and methods generated when C# code is compiled into cpp code using il2Cpp
  • unity builtin_extra: shaders that are always included
  • All active scenes in BuildSettings
  • Resources in the Resources folder, and other resources referenced by those resources
  • Global settings and referenced resources, such as splash images, etc.

You can use AssetStudio to view all resources inside the file.

When downloading or updating the first resource package for the first time, it must be downloaded in the early stage of minigame startup, so the file size greatly affects the game's startup speed.

  • Network conditions are mostly wifi or 4G (also, ads can specify network conditions)
  • The average player download speed is about 2MB/s
  • There are quite a few low-network-speed players with <300KB/s
  • Be sure to compress the first resource package: check "Compress first resource package" in the conversion panel, or enable "gzip/br compression" for the first resource package (with the .txt suffix) in the CDN management backend
  • Chinese display requires custom fonts, packaged into the first resource package or a Bundle; please try to use a streamlined font within 2~3MB to avoid affecting game startup speed

Recommendation: Be sure to compress the first resource package for transmission, and use the network tab of the developer tools to confirm the transmitted size; the network transmission size should be controlled to 3~5MB.

2.2.2 WASM Code Download and Compilation ​

The size of the WASM sub-package directly affects the code download time and the program initialization compilation time. Regarding the impact of WASM code on startup speed, developers need to note:

  • The conversion tool automatically applies br compression to the Unity WebGL package (compressed to 20% of the original code package)
  • WASM code is downloaded in parallel with the first-package resources, so it takes up download bandwidth
  • WASM compilation requires CPU resources, and the time is still considerable for low-end devices

We recommend that the original code package (the code file under the webgl/Build directory) not exceed 30MB, and we recommend developers check "Strip Engine Code" and set "Managed Stripping Level" to High. At the same time, we strongly recommend developers use a code sub-packaging tool to reduce the code package to 1/3 of its original size. If using Unity 2021 or above, you can change the IL2CPP option in the PlayerSettings panel to a smaller size (SIZE) to reduce the number of functions.

2.2.3 Engine Initialization and Developer First-Frame Logic ​

The first-scene time shown in the timelog is the engine initialization and the developer's first-frame logic. Regarding the time of this stage, developers need to note:

The first-frame Start/Awake of MonoBehaviour scripts should have as little logic as possible, prioritizing presenting the screen. The initial scene should not be too large; usually presenting the Splash scene is sufficient. When the initial scene needs to subsequently load the main scene or configuration, a frame-slicing strategy can be adopted; never block in Start/Awake. For computation time, please use the Android CPU Profiler for performance tuning to analyze the time-consuming parts of each frame. We recommend developers use the pre-download feature, which can use the network idle period of this stage to download resources.

2.2.4 In-Game On-Demand Resource Loading ​

Earlier we mentioned that developers need to separate resources from the first package to reduce first-screen loading time. Similarly, for the remaining resources, developers had better load them on demand to reduce the waiting time for players to reach core gameplay. For optimization, refer to Use Addressable Assets System or AssetBundle for on-demand resource loading.

3. Common Startup Optimization Techniques ​

When you have analyzed that the minigame needs startup optimization, please continue reading:

Use Addressable Assets System for on-demand resource loading First-scene startup optimization Shader async Warmup

4. Common Startup Optimization Tools ​

An open-source resource viewing tool that can inspect the resource content of the data first package as well as AssetsBundle (or the new Addressable). It is very helpful for analyzing the correctness and redundancy of packaged resources.

A great frontend tool for viewing Unity build information. BRT shows the storage space occupied by each resource included at build time, as well as unused resources.

4.3 Asset Hunter ​

A resource cleanup plugin that can clean up useless resources in a project.

4.4 Unity Addressable Assets System ​

Unity's brand-new resource management workflow.