⚙️ Performance optimization

A kit that helps you optimize the performance of your game.

What is PerformanceKit?

As we mentioned before in What is Trail? there are two parts to the Trail ecosystem; the SDK and the platform. PerformanceKit works mainly on the platform with some hooks in the SDK. Primarily, PerformanceKit is responsible for optimizing and patching your game, making sure that it runs as close to the native experience as possible and as easily as possible.

PerformanceKit in the platform

On the Trail platform -- after you've uploaded your game, we automatically apply some post-processing to your build. 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 as mentioned in the 🗄️ FileKit article.


Unity Build Compression

We recommend that you disable build's compression in Unity's Publishing Settings since Trail will handle that for you as mentioned above.

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.

PerformanceKit in the SDK

In the SDK we hooked a few methods for you to help 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 = SDK.PerformanceKit.GetRecommendedResolution();
    Result result = SDK.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 = SDK.PerformanceKit.GetRecommendedResolution(out var resolution);

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

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