BitSwarmClient.Send creates 1MB of GC Allocations

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
lggstef
Posts: 10
Joined: 14 Jun 2019, 20:13

BitSwarmClient.Send creates 1MB of GC Allocations

Post by lggstef »

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.

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
Attachments
NetworkObjectUpdateGCAlloc.png
(133.05 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: BitSwarmClient.Send creates 1MB of GC Allocations

Post by Lapo »

Hi,
thanks for reporting, we'll look into it and let you know.

Are you using the DEBUG feature of the API? If that's the case it may cause extra garbage to be generated due to the hex dumps that are logged for every packet sent/received.

If so try testing again with the ConfigData.Debug property set to false.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
lggstef
Posts: 10
Joined: 14 Jun 2019, 20:13

Re: BitSwarmClient.Send creates 1MB of GC Allocations

Post by lggstef »

Hi Lapo,

Thank you for your response. We did have debug set to true. Setting it to false did reduce the gc alloc quite a bit, to around 100-135KB.

Thanks!
Post Reply