3mb GC alloc on every Send
Posted: 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.
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.
Code: Select all
Profiler.BeginSample("Send UserVars");
sfs.Send( new SetUserVariablesRequest(userVars) );
Profiler.EndSample();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.