Page 1 of 1

3mb GC alloc on every Send

Posted: 24 Jun 2021, 23:20
by Nexic
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.

Re: 3mb GC alloc on every Send

Posted: 25 Jun 2021, 14:35
by Lapo
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

Re: 3mb GC alloc on every Send

Posted: 25 Jun 2021, 21:38
by Nexic
Thanks a bunch, that would be very handy indeed. Email sent :)