Garbage Collection Issue

Options
Hello Tobias or anyone else too,

Is there any way around the amount of garbage collection/memory allocation issues that happen from the Sending of outgoing commands in the Photon Handler script?

Are there a lot of strings or arrays that could be optimized better? I've been working on my project for about 2-3 months now (all centered around PUN as my networking solution) and only just found out about the amount of garbage being generated by this script (or a command from it). It is currently making my game un-releasable in any real sense.

I am making an RTS, and whenever I get to around 10+ units in my game, the framerate will drop to essentially "zero" every 8-12 seconds or so, or whenever I issue a move command to a lot of units. I am using "unreliable on change" for most of the units. The spikes are very noticeable, and currently my game cannot be played with this issue.

Perhaps someone could help me fix it myself, assuming I have access to whatever may be causing the garbage (I'm guessing it's turning a lot of the information into strings or arrays that cause a huge amount of this).

Here is the issue in the profiler:



Comments

  • Tobias
    Options
    We can possibly do something about it but at some level, sending stuff (sadly) generates garbage. We have to turn your updates and RPCs into byte[] and send that. Some of that memory can't be re-used (effectively).

    Make sure to update to the latest PUN version from the Asset Store. v1.66 has some improvements to optimize GC.


    Please do a "deep profile" session.
    I wonder why SendOutgoingCommands has to be called 8x in this one frame.

    I guess some of the garbage avoidance will mean to refactor messages, too. The less you write, the better.