question

corporate avatar image
corporate asked

PlayFabHttp.Update() being called every frame?

While using Unity 2018.1 with the latest PlayFab SDK, I noticed that PlayFabHttp.Update() is executing every frame, generating 488 bytes of garbage. This cannot be intended behavior, can it?

As far as I know, there's nothing in my code that should trigger such update frequency. Is this a known issue? I don't believe I've seen such behavior before in earlier SDKs. screenshot.png

unity3dsdks
screenshot.png (65.1 KiB)
10 |1200

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

Andy avatar image
Andy answered

Digging in, it appears to be intentional, though I don't think the impact was well-considered. It's from the Plugin Manager that we started roughing in at the beginning of August (https://api.playfab.com/releaseNotes/#180809). I'm filing a bug on our SDK team to investigate a better way of introducing this infrastructure and, at least, providing a toggle for the functionality.

2 comments
10 |1200

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

corporate avatar image corporate commented ·

Thanks, @Andy! In the meantime, would the world end if I were to comment out the offending code?

        private void Update()
        {
            /*
            var transport = PluginManager.GetPlugin<ITransportPlugin>(PluginContract.PlayFab_Transport);
            if (transport.IsInitialized)
            {
                if (_apiCallQueue != null)
                {
                    foreach (var eachRequest in _apiCallQueue)
                        transport.MakeApiCall(eachRequest); // Flush the queue
                    _apiCallQueue = null; // null this after it's flushed
                }
                transport.Update();
            }
            #if ENABLE_PLAYFABPLAYSTREAM_API && ENABLE_PLAYFABSERVER_API
            if (_internalSignalR != null)
            {
                _internalSignalR.Update();
            }
            #endif
            */
        }
0 Likes 0 ·
Andy avatar image Andy ♦♦ corporate commented ·

While the world wouldn't end, commenting that entire function out would mean the PlayFab SDK would stop working. Instead, it should be changed such that we only call GetPlugin<ITransportPlugin>() once and then reuse the result for subsequent calls. I or someone on the SDK team will probably be putting together a pull request to correct this soon, though you're welcome to give it a shot. :)

0 Likes 0 ·
robert avatar image
robert answered

Any progress on this one? A GC Alloc (from PluginManager.GetPlugin) for each frame has quite a performance impact. We workaround this locally by caching transport from PluginManager.GetPlugin() in PlayFabHttp.Update() for now

private void Update()
{
    if (transportPlugin == null)
      	transportPlugin = PluginManager.GetPlugin<ITransportPlugin>(PluginContract.PlayFab_Transport);
    if (transportPlugin.IsInitialized)
    {
	....
10 |1200

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

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.