Mir 2 improves rendering performance by using Swappy

Mir 2: Return of the King is a high-quality Legend IP mobile game authorized by Actoz Soft and developed by HK ZHILI YAOAN LIMITED using Unity Engine.

This game not only perfectly recreates the feelings of "Mir 2", a representative of Korean fantasy MMORPG, but also offers many of the most popular game contents, such as equipment collection, large-scale sand attack and other core gameplay.

The game used Android Frame Pacing API (Swappy) to improve the stability of its frame rate, achieve smooth rendering and significantly boost their Android Vitals (Slow Session metric).

Slow Session launched on Android Vitals

Slow Session is an Android vitals metric in Google Play console. A slow session has more than 25% slow frames. A frame is slow if it is:

1) At 20fps, it is not presented within 50ms after the previous frame. 2) At 30fps, it is not presented within 34ms after the previous frame.

In due course, Play will start steering users away from games that cannot achieve 20 FPS on their phones.

There are many reasons a frame might present or render longer on the screen than the developer's target. The game could be CPU or GPU bound, overheating which activates a throttled thermal state, or there's a mismatch in the game's framerate and the device's display refresh rate.

What is Swappy

The Android Frame Pacing library, also known as Swappy, is part of the AGDK libraries. Swappy helps OpenGL and Vulkan games achieve smooth rendering and correct frame pacing on Android.

The library handles multiple refresh rates if they are supported by the device, which gives a game more flexibility in presenting a frame. For example, for a device that supports a 60 Hz refresh rate as well as 90 Hz, a game that cannot produce 60 frames per second can drop to 45 FPS instead of 30 FPS to remain smooth. The library detects the expected game frame rate and auto-adjusts frame presentation times accordingly.

The Frame Pacing library also improves battery life because it avoids unnecessary display updates. For example, if a game is rendering at 60 FPS but the display is updating at 120 Hz, the screen is updated twice for every frame. The Frame Pacing library avoids this by setting the refresh rate to the value supported by the device that's closest to the target frame rate.

How Mir 2 improved Rendering performance with Swappy

Mir 2 (미르2: 왕의 귀환) was facing an issue with unstable rendering performance where they experienced 40% Slow Sessions at a framerate threshold of 20 FPS, much higher than Google Play's 20% threshold.

Figure 1. Slow session metric before integrating Swappy.

Mir 2 (미르2: 왕의 귀환) is a high fidelity graphic game, some devices are facing challenges to maintain a stable FPS. Their frame rate distribution shows lots of sessions are running at FPS lower than 20fps.

Figure 2. The game's FPS distribution before integrating Swappy.
Each bucket represents the percentage of sessions where 75% of their frames were faster than the bucket label.

When the display workload takes longer than the application workload, additional frames are added to a queue. This leads, once again, to stuttering and may also lead to an extra frame of latency due to buffer-stuffing.

Figure 3. Long frame B gives incorrect pacing for 2 frames—A and B.

The Swappy library solves this by using sync fences (EGL_KHR_fence_sync and VkFence) to inject waits into the application that allow the display pipeline to catch up, rather than allowing back pressure to build up. Frame A still presents an extra frame, but frame B now presents correctly.

Figure 4. Frames C and D wait to present.

Mir 2 easily integrated Swappy library by leveraging Unity's built in Optimized Frame Pacing feature. The action resulted in significant improvement for their rendering performance, specifically dropping the Slow Session metric from 40% to 10%.

Figure 5. Slow Session improvement after integrating Swappy.

The number of slow sessions have been reduced significantly for Mir2 after they integrated Swappy.

Figure 6. The game's FPS distribution after integrating Swappy.
Each bucket represents the percentage of sessions where 75% of their frames were faster than the bucket label.

Get Started with Swappy

How to use Swappy in native game engines

See the following guides to integrate the Android Frame Pacing library into your game:

How to use Swappy in Unity game engine

Unity has integrated Android Frame Pacing into their engine. To enable this feature in Unity, check the Optimized Frame Pacing checkbox under Project Settings > Player > Settings for Android > Resolution and Presentation:

Figure 7. Enable Frame Pacing in Unity Engine.

Alternatively, programmatically enable the Optimized Frame Pacing option in your logic code to allow Unity to evenly distribute frames for less variance in frame rate, creating smoother gameplay.

How to use Swappy in Unreal game engine

Unreal 4.25 and above integrates Android Frame Pacing Library, which is part of the Android Game Development Kit. The Mobile Frame Pacing article explains how to enable the Android Frame Pacing Library and how to control frame pacing from C++ code.

For further reading, you can learn about Slow Sessions and Swappy.