question

Niklas Gawell avatar image
Niklas Gawell asked

PlayFab Unity SDK: First invokation of PlayFabHttp.MakeApiCall blocks for almost a second. How do we initialize PlayFabHttp so it does not freeze the game.

We are creating a game for Oculus Quest where we use PlayFab with the Unity SDK.

On startup, after all essential assets are loaded, we want to login to PlayFab. We do this using customId. This is the first interaction we do with the PlayFab Apis. In our profiler we can see that within PlayFabHttp.MakeApiCall it spends more than 900ms, which blocks our main thread. Causing a severe frame drop.

This only happens the first time, but it still a problem. Is there a way to initialize PlayFabHttp async?

Or can we pre warm it somehow to get the initialization in smaller chunks?

unity3d
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sarah Zhang avatar image
Sarah Zhang answered

>> This only happens the first time, but it still a problem. Is there a way to initialize PlayFabHttp async? Or can we pre warm it somehow to get the initialization in smaller chunks?

Could you please tell us, do you wait until the player logs in before continuing to render the game screen?

As far as I know, the first call would make a long time, but it should not block the main thread as we used Unity Coroutine.

The first API call needs to wait for 1 second to get the response. Because the first DNS resolution time would a little bit longer. You can let the client send an HTTP request to a meaningless URI such as https://[YourTitleId].playfabapi.com/ to let it make the first DNS resolution before you call the first API. For example, you can send the first HTTP request when you load the first scene asynchronously.

Besides, you can feel free to modify our Unity SDK code to meet your requirements, such as using multiple threads.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Niklas Gawell avatar image
Niklas Gawell answered

Hi,

thanks @Sarah Zhang for your reply. We have investigated this a bit further. It seems the problem goes away if we set

PlayFabSettings.CompressApiData = false

We are still looking into why that would have an effect.

We do not transfer huge amounts of data (not yet at least). Would we suffer in anyway from turning that off?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sarah Zhang avatar image Sarah Zhang commented ·

Thanks for sharing, we find the PlayFabSettings.CompressApiData will affect the GZIP compress. It is unknown whether it will affect your project, you can use it according to the actual testing results. You can find the following code in PlayFabUnityHttp.cs in your project.

   public void MakeApiCall(object reqContainerObj)
        {
            ...

#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
            if (PlayFabSettings.CompressApiData)
            {
                reqContainer.RequestHeaders["Content-Encoding"] = "GZIP";
                reqContainer.RequestHeaders["Accept-Encoding"] = "GZIP";


                using (var stream = new MemoryStream())
                {
                    using (var zipstream = new Ionic.Zlib.GZipStream(stream, Ionic.Zlib.CompressionMode.Compress,
                        Ionic.Zlib.CompressionLevel.BestCompression))
                    {
                        zipstream.Write(reqContainer.Payload, 0, reqContainer.Payload.Length);
                    }
                    reqContainer.Payload = stream.ToArray();
                }
            }
#endif
...
        }

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.