in0finite / SanAndreasUnity

Open source reimplementation of GTA San Andreas game engine in Unity
https://discord.gg/p6jjud5
MIT License
2.15k stars 353 forks source link

Reduce GC allocations #40

Open in0finite opened 4 years ago

in0finite commented 4 years ago

GC causes a lot of freezes in the mobile version.

Here are the screenshots of profiler showing what is allocating the memory (at commit 7725dfb):

Complete list complete list imGUI details GUI details behaviour update details behaviour update details


As of version 3.2, GC is freezing the Android game on every 10 seconds, when running at 17 FPS in Demo scene.

As we can see, 7.9 KB out of 11.7 KB (67 %) is taken by imGUI. By converting imGUI to uGUI (see #52 for in-game UI) and using a single OnGUI() function, we can reduce 7.9 KB to only 0.4 KB.

This should be profiled again because #52 is done.

After #106 is done, there will be only a few usages of imGUI, so the most of GC allocations will be done by game logic. Also, this ticket will probably not be important anymore, so it can be closed at that moment.