Graphic.UpdateMaterial memory allocations

While profiling our game, I’m seeing various memory allocations, all related to uGUI, for example in Graphic.UpdateMaterial:

Looks like each of the game objects under the canvas is performing a lookup to see the canvas it belongs to. This makes a huge amount of GetComponent calls (traverses the hierarchy up until a canvas is found).

I wonder if there could be a solution (requires a modification to the UI code) where each element would already store a reference to the canvas, avoiding the need for this lookup.

Is such a solution possible? or what would be the better way of overcoming this specific allocation ?

I submitted a bug relating to performance of MaskUtilities.FindRootSortOverrideCanvas etc which walk your UI objects from the children up thru each parent checking to see if its a canvas causing a load of allocation and CPU time to be spent. It was closed as ‘by design’.

1 Like

I wish someone “official” could comment on this, and whether there’s anything planned to improve both CPU performance and memory consumption related to the UI and particularly to this method

@NeilW Do you have a bug number that was closed?

@liortal yes there are plans to improve both as we go, but i cant say for sure when any of it is happening. If you notice something bad file a bug.

Thanks for replying Phil.

I just recently started working with uGUI, and i see high memory allocations and in general things that are not yet super optimized.

BTW I already submitted a PR for one thing - you can have a look - https://bitbucket.org/Unity-Technologies/ui/pull-requests/30/correct-the-calculation-for-the-needed

BTW 2 - i just submitted a performance related bug (due to UnityEvents allocating lots of memory, not sure it’s 100% UI related). Here’s the thread related to that: http://forum.unity3d.com/threads/unityevents-are-generating-lots-of-garbage.362617/

Cool, yea i should spend some time soon going through the PR and see what we can take.

I’ll talk to the guy about the UnityEvents, They aren’t UI specific and i dont know much about the workings internally.

1 Like