BitSwarmClient.Send creates 1MB of GC Allocations
Posted: 12 Sep 2023, 15:55
Hi, we are running into a problem with BitSwarmClient.Send creating around 1MB of GC allocations when we send networked object updates. We are using Smartfox C# API for Unity.
A little context for our situation:
Part of our VR multiplayer experience includes having players hang out in a virtual environment with their avatars, similar to VRChat. These environments contain objects that players can interact with, so they need to be synced over the network (data like transform data, who's holding it, etc). Data gets sent at a rate of 10 updates per second. We also only send networked object updates when there is an update to send, so if an object is just sitting around unchanged, we will not sending anything. The GC alloc seems to be coming from sending object data though. I've attached a screenshot of our profiler.
The code to send the object data is as follows. Most network object variables get sent via udp.
Is there anything we can do to reduce this? One of our platform targets is Oculus Quest, so we're really feeling these spikes.
For reference, we're using Unity 2021.3.16, Smartfox C# client API v1.8.3, and SmartFoxServer v2.18.0
A little context for our situation:
Part of our VR multiplayer experience includes having players hang out in a virtual environment with their avatars, similar to VRChat. These environments contain objects that players can interact with, so they need to be synced over the network (data like transform data, who's holding it, etc). Data gets sent at a rate of 10 updates per second. We also only send networked object updates when there is an update to send, so if an object is just sitting around unchanged, we will not sending anything. The GC alloc seems to be coming from sending object data though. I've attached a screenshot of our profiler.
The code to send the object data is as follows. Most network object variables get sent via udp.
Code: Select all
ISFSObject data = new SFSObject();
data.PutSFSObject(SFSNetworkKeys.OBJECT, obj);
data.PutUtfStringArray(SFSNetworkKeys.CHANGED_VARIABLES, objChangedVariables);
data.PutBool(SFSNetworkKeys.UDP, useUdp);
Sfs.Send(new ExtensionRequest(SmartfoxMessages.Request_NetworkedObjectVariablesUpdate, data, sfsRoom, useUdp));Is there anything we can do to reduce this? One of our platform targets is Oculus Quest, so we're really feeling these spikes.
For reference, we're using Unity 2021.3.16, Smartfox C# client API v1.8.3, and SmartFoxServer v2.18.0