3mb GC alloc on every Send

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

Moderators: Lapo, Bax

Nexic
Posts: 31
Joined: 26 Jun 2008, 12:23

3mb GC alloc on every Send

Postby Nexic » 24 Jun 2021, 23:20

We've recently been trying to optimize client side performance of our game as much as possible, and one major hurdle we're facing is the sheer amount of memory allocated by the C# api every time we try and send something. Using Unity's profiler we have determined that this exact line of code is causing 3mb (or more) of memory to be allocated, and we are running this 5-10 times per second.

Code: Select all

Profiler.BeginSample("Send UserVars");
sfs.Send( new SetUserVariablesRequest(userVars) );
Profiler.EndSample();


As an experiment, I tried caching a single reference to a SetUserVariablesRequest and simply sending that over and over. This then reduced the allocation to practically zero. The problem here is of course that this isn't actually a solution to the problem, as we need to tell the server of the changed user variables and for some reason these classes seem to be read only.

Surely there must be some way to send a simple data packet without allocating so much memory? And if there isn't, would it be possible to get the Unity api source code so that I can at least attempt to optimize it myself? For the record I've spent close to 20k EUR on licenses so far.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: 3mb GC alloc on every Send

Postby Lapo » 25 Jun 2021, 14:35

Hi,
the allocation is likely due to the fact that requests and parameters are abstractions that are easy to use, instead of having to write wire-level, binary-encoded data in your code.

In other words you can send high level objects that are serialized and translated in "packet format" by the API themselves, at some memory cost, due to the creation of short-lived intermediary objects.

Surely there must be some way to send a simple data packet without allocating so much memory? And if there isn't, would it be possible to get the Unity api source code so that I can at least attempt to optimize it myself? For the record I've spent close to 20k EUR on licenses so far.

Yes it is possible to request the sources.
Please drop us an email to our support@... email box, with a reference to this post.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Nexic
Posts: 31
Joined: 26 Jun 2008, 12:23

Re: 3mb GC alloc on every Send

Postby Nexic » 25 Jun 2021, 21:38

Thanks a bunch, that would be very handy indeed. Email sent :)

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 36 guests