gizmos icon indicating copy to clipboard operation
gizmos copied to clipboard

GC Alloc

Open FreedTerror opened this issue 1 year ago • 4 comments

Anyway to reduce or eliminate the memory allocation being created? Screenshot_3

I'm using your gizmos to display hitboxes. It works really well! Screenshot_4

FreedTerror avatar Aug 01 '23 21:08 FreedTerror

i can try but i cant guarantee ill do it :p, if you find a solution to the root cause i can review the pr with you (theres likely areas that could be improved with how memory is used)

popcron avatar Aug 02 '23 19:08 popcron

In the draw method public static void Draw<T>(Color? color, bool dashed, params object[] args) where T : Drawer the only spot that seems to allocate memory each time the method is called is this Vector3[] array = new Vector3[points]; // Allocates memory each time. We could look into using lists at the class level to solve this but, it seems like most of your code base uses arrays so it would require a bit of work to switch the arrays over to lists.

FreedTerror avatar Aug 03 '23 00:08 FreedTerror

i could see it becoming an array rented from ArrayPool<Vector3>.Shared and then returned after being used/consumed after drawing, trying to figure out why it wasnt like that in the beginning though lol

popcron avatar Aug 03 '23 21:08 popcron

Yeah ArrayPool<Vector3>.Shared sounds promising. I've never actually knew that class existed until now. The changes I tried making to avoid memory allocation ended up breaking the code completely.

FreedTerror avatar Aug 03 '23 23:08 FreedTerror