⚙️ Performance Optimization

What is PerformanceKit (in the SDK) and what does it do?

Trail does quite a bit of optimization, compression, and post-processing to increase game performance for you - automatically! Apart from that, in this article, you can learn how to force game resolutions through code.

PerformanceKit in the SDK

There are two parts to the Trail ecosystem; the SDK and the Trail Game Manager (the Platform). PerformanceKit works mainly on the platform with some hooks in the SDK.

📘

PerformanceKit

PerformanceKit gives you the tools to control the game resolution from your game. On mobile, the device will set the resolution at startup. On web the user can resize the window, change between fullscreen and windowed mode, as well as other

PerformanceKit lets you adjust the resolution during runtime, making this experience great (instead of buggy).

PerformanceKit in the SDK has a set of methods to help you optimize the player experience. The primary use of these is setting the resolution to what is best for your player.

🚧

Changing resolution using Unity

The reason behind us offering this feature in the SDK is because on WebGL you're unable to do that using Unity directly.

Let's look at some code:

// Remember to initialize the SDK first.

// Code you may have to set resolution; could be in the Options menu or start of your game. 
private void AdjustResolution()
{
    Resolution resolution = Trail.PerformanceKit.GetRecommendedResolution();
    Result result = Trail.PerformanceKit.SetResolution(resolution);
    
    if(result.IsError()) {
        Debug.LogErrorFormat("Failed to set resolution: {0}", result);
    }
}

// If you want to double check the result of the get/set resolution methods, you can do:
private void AdjustResolution()
{
    Result getResult = Trail.PerformanceKit.GetRecommendedResolution(out var resolution);

    if (getResult.IsError()) {
        Debug.LogErrorFormat("Failed to get recommended resolution: {0}", getResult);
    }
    
    Result setResult = Trail.PerformanceKit.SetResolution(resolution);

    if(setResult.IsError()) {
        Debug.LogErrorFormat("Failed to set resolution: {0}", setResult);
    }
}

Performance from the Game Manager

In the Trail Game Manager post-processing is automatically applied to your build (after uploading it through the SDK). This is not to be confused with Unity's visual Post Processing stack. Our post-processing targets performance optimizations; it goes through the build and tries to optimize the game's code by applying a few patches providing an extra "edge" when running on WebGL. Once the post-processing is done, the build undergoes a compression process. One of the things this compression does is apply Brotli compression to the whole build - including your Asset Bundles if you're using them (Read about FileKit here).

📘

Unity Build Compression

We recommend that disabling build's compression in Unity's Publishing Settings. Trail handles compression for you. The SDK will automatically offer to disable compression for you when it analyzes your game.

But the main thing to note here is that we do all of this for you, automatically without you having to worry about it.

📘

Post-processing and compression process

Both the post-processing and compression processes take time and how long they would take depends on the size of your game and how many assets it has. However, a player (including you) can run the game during this process. Note, however, when you do that, you're running the game without optimization and the performance you experience shouldn't be used as an indicator.