Search Unity

TextMesh Pro Performance issues related to culling of UI that is not being rendered.

Discussion in 'UGUI & TextMesh Pro' started by Lukas-Wendt, Oct 4, 2019.

  1. Lukas-Wendt

    Lukas-Wendt

    Joined:
    Jun 1, 2014
    Posts:
    13
    There is a lot of UI in our game. We have followed this guide https://learn.unity.com/tutorial/optimizing-unity-ui#5c7f8528edbc2a002053b5a2 to avoid common pitfalls (like expensive enabling/disabling). We are facing an issue where culling of UI is taking up a lot of time. By activating deep profile, it became apparent that TMP_UpdateManager.OnCameraPreCull(), and the calls from that method, was eating up a good chunk of time.

    If I enable/disable a group of UI elements by enabling/disabling the top GameObject, the culling no longer occurs. If I enable/disable the group by enabling/disabling the Canvas to which the group belongs, nothing is rendered but the culling is still taking place.

    Have any of you had to deal with this issue? Is there anyway to skip culling of UI elements with disabled Canvases?

    I hope someone can help - any input is appreciated.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The text objects are processed / rendered just before culling takes place which is OnCameraPreCull(). Disabling OnCameraPreCull() will prevent all text objects from rendering.

    What we need to look at in terms of performance impact is the number of text objects being re-generated as unless the content of these text objects change every frame, there should not be any processing of those.

    Any change you can supply me with some repro of the project to look at? The easiest way is to submit a bug report with the project and then provide me with the Case # so I can go grab it.
     
  3. Lukas-Wendt

    Lukas-Wendt

    Joined:
    Jun 1, 2014
    Posts:
    13
    Hi Stephan, thank you for your reply.

    I'm not able to send the project I'm working on, but I have uploaded a small project with a description, that can at least illustrate the challenge that we are facing. I have not received a case number yet, but I will post it here as soon as I do.

    We are trying to enable/disable groups of UI by enabling/disabling the Canvas to which they belong. But what we are seeing is that a disabled Canvas is roughly as expensive (in CPU time) as an enabled one - due to the culling in OnCameraPreCull(), which takes place regardless of the Canvas being enabled or disabled.

    We could of course enable/disable the entire game object, but that creates a very noticeable stutter, due to what I imagine is rebuilding and rebatching.
     
  4. Lukas-Wendt

    Lukas-Wendt

    Joined:
    Jun 1, 2014
    Posts:
    13
    The case number is: 1189820
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I may have a solution for you to test. Please send me a private message so I can provide you with a special version of TMP for Unity 2018.4 for testing.
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    Please keep us posted here to, as I'm watching this thread :)
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Will do :)
     
    Peter77 likes this.
  8. IkigaiMonkey

    IkigaiMonkey

    Joined:
    Sep 22, 2012
    Posts:
    18
    I'm having the same issue in 2019.1, just enabling for first time a gameobject with a single TMPro text is consuming almost 40ms, which I think it's exessive and the game has a noticeable stutter. Is there any workaround? I don't remember having this in the past
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    There are several things that can affect the initial enabling of a text object.

    First, there is initial overhead related to loading the resources needed by TMP such as those assigned in the TMP Settings like default font asset, fallbacks, and other assets. Shaders also need to be loaded and potentially compiled based on various project settings. Loading of some of these resources will be different in a build vs. Editor.

    Using Dynamic vs. Static font assets will also have an impact depending on the amount of text this text object contains.

    Text object settings such as auto-size and structure of the scene hierarchy like Layout Components, content size fitters, will all contribute to this initial potential overhead.

    I will need more information on your setup to try to figure out if this is normal or the result of potential changes in 2019.1 or settings.

    P.S. I would recommend testing with the latest release of TMP for 2018.4 which is version 1.5.0-preview.1 vs. 2019.1 with version 2.1.0-preview.1. See if you get the same results enabling a similar text object in some new project / simple scene.
     
    IkigaiMonkey likes this.
  10. Lukas-Wendt

    Lukas-Wendt

    Joined:
    Jun 1, 2014
    Posts:
    13
    @Stephan_B, @Peter77 and other interested people.

    I just tested TMP 1.5.0-preview.2, and I'm no longer seeing issues with TMP_UpdateManager.OnCameraPreCull() doing work on text objects on disabled canvases.

    Thanks for the quick fix!
     
    IkigaiMonkey, Stephan_B and Peter77 like this.