UGUI.Rendering.UpdateBatches takes a lot of CPU

Hi there! Unity 2017.4.27f .Is this a regular behaviour ? This is static scene with 24 batches and 17 setpass calls.

1 Like

Here is my profiler in Editor with same metrics


My UI profiler

Iā€™ve tried to optimize UI and replace Mask to RectMask2d, and it becomes 2.5x slower. Why me scene so slow on android device? Any suggestions?

Hello @LeonhardP , can you please confirm if the fix mentioned in

is included in 2017.4.24f1 or 2017.4.27f1?

Like justtime, Iā€™m having a very significant hit in UpdateBatches:

Itā€™s important since Iā€™m aiming 60fps.
Also, do you have any tips to profile UI? I donā€™t know if this is normal or too high, but I have a really simple UI at this stage, it should perform well.
Iā€™m using 2017.4.24f1 and profiling from a iPad mini 4.

I had (have) this exact problem and I am not sure if this is the same thing but just throwing it out there just in case some have the same setup as me. In my case it turned out that I was using an animator to change colors of a text (TMPRO). I guess every time something is changed in the UI it has to redraw that whole element. This one little animated text cost over 20ms. I havenā€™t found a ā€œgoodā€ solution for this yet -just gave up for now and removed the animation.

I guess I can create a mesh of this with text typed into the texture and remove it from UI and place it as a decal.

@roberto_sc what profiling tool are you using in your screenshot, I havenā€™t see that before?

That is correct. See ā€œUI Canvas rebuildsā€ in the following document for an explanation:
https://learn.unity.com/tutorial/optimizing-unity-ui#5c7f8528edbc2a002053b5a2

You can also see in the UI code, whenever Unity notifies the UI that any animation property changed, the UI dirties and rebuilds everything:
https://bitbucket.org/Unity-Technologies/ui/src/31cbc456efd5ed74cba398ec1a101a31f66716db/UnityEngine.UI/UI/Core/Graphic.cs#lines-749

Unity Technologies solution to this, as discussed in some Unite talks and probably learning material as well, is to split the UI across multiple Canvases. If you have UI elements that change frequently, move them to a separate Canvas, so Unity does not have to rebuild UI elements that are not on that Canvas.

Thanks. Yeah, I have already seen those talks (it is in Unity optimization talks by Ian), and I already tried placing the text in question under a separate Canvas it was only slightly better, no significant improvement. Maybe this also has something to do with text being updated every frame. I am not sure how exactly this is done in TMPro underneath. It is a world space canvas some not sure if these work differently as far as updating goes. Best I have come up with is not to use the UI. Just create a mesh and type out the text to that and just animate the material color.

P.s. I did have this canvas as a child canvas of the root. Does it have to be a completely separate canvas?

ā€œSeparate canvasā€ in the sense that it needs to have a different Canvas Component. According to my test, it does not make a difference whether Canvases are siblings or nested.

For example, in this test:
4868579--469244--upload_2019-8-18_8-54-20.png

The ā€œScroll Viewā€ contains a gazollion UI elements and itā€™s very slow to update. However, if I enter text in the ā€œInputFieldā€, which is part of ā€œSub Canvasā€, Unity only rebuilds the ā€œSub Canvasā€ part, but not the elements under ā€œScroll Viewā€.

I tested it with Unity 2019.1.2f1, test scene attached.

4868579ā€“469247ā€“scene.zip (285 KB)

1 Like

Yeah thatā€™s what I gathered also. In my case itā€™s literally a canvas, background image and a Text element (TextMeshPro) -see attached. All I am doing is updating the text color and this massive spike. I am also in VR so that probably doesnā€™t help things. I will revisit this later try to figure this out. I will share what I find.

Maybe this is part of the problem that talks about on this thread. Well at least in my case this is a non-essential item so I am going to push this aside for now and move on to the next.

4869713--469469--Capture.PNG

Thanks for these links, I will take a look.

In my case performance was bad because the main canvas had its render mode set to a camera that was moving all the time.

@FlightOfOne thatā€™s the profile analyzer, itā€™s awesome: Unity Blog

Awesome! Thank you.

Hi ! Whatā€™s your proifle tool used? Itā€™s interestingļ¼