Search Unity

UGUI.Rendering.UpdateBatches takes a lot of CPU

Discussion in 'UGUI & TextMesh Pro' started by justtime, May 11, 2019.

  1. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi there! Unity 2017.4.27f .Is this a regular behaviour ? This is static scene with 24 batches and 17 setpass calls.
     
    FlightOfOne likes this.
  2. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    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?
     
  3. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    144
    Hello @LeonhardP , can you please confirm if the fix mentioned in

    https://forum.unity.com/threads/ugui-rendering-updatebatches-performance-regression.496849/
    https://forum.unity.com/threads/ugui-rendering-updatebatches-performance-still-bad.517499/
    https://forum.unity.com/threads/ugui-rendering-updatebatches-performance-problem.504553/

    is included in 2017.4.24f1 or 2017.4.27f1?

    Like justtime, I'm having a very significant hit in UpdateBatches:

    upload_2019-7-10_10-30-33.png

    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.
     
  4. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    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?
     
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    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-Technol...b/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.
     
  6. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    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?
     
  7. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    "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:
    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.
     

    Attached Files:

    forestrf likes this.
  8. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    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.
     

    Attached Files:

  9. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
  10. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    144
  11. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
  12. meichen8050753

    meichen8050753

    Joined:
    Jan 16, 2017
    Posts:
    37
    Hi ! What's your proifle tool used? It's interesting!