Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

TextMesh Pro TextMeshProUGUI.LateUpdate() = performance spike

Discussion in 'Unity UI & TextMesh Pro' started by serbusfish, Oct 9, 2018.

  1. serbusfish

    serbusfish

    Joined:
    Dec 27, 2016
    Posts:
    223
    For some reason I keep getting regular performance stutters and according to the profiler it is caused by TextMesh late update. I installed TextMeshPro today, I dont believe I have used it in a way that should cause performance issues, I created 6 separate UI objects, and one of my scripts can change the text during gameplay, that's really all i've done?
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    2,633
    TextMesh Pro does use LateUpdate() to check if the scale of the text objects has changed between frames. However, unless you have a lot of text objects, you should not see any measurable performance impact from this.

    Can you post an example of the script you are using to change the text?

    P.S. In the next release of TMP due in part to the [ExecuteInEditMode] attribute being deprecated for Unity 2019.1, TextMesh Pro will be using an update manager instead of LateUpdate(). This will result in a slight performance improvement.
     
  3. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    20
    I have 1535 TextMesh instances in scene, it takes 0.64ms.
    That's quite expensive for doing 'nothing'.

    If it would be possible to disable such detection on per-instance basis, I'd disable it on 99.5% of instances.

    If it would be possible to disable only globally for all TextMeshes, I'd be okay with that too.
    I can add component to 0.5% which would do that.

    To be sure, I'm talking about text meshes on 3d objects in 3d scene, not UGUI canvas texts.
    I can imagine it's not problem for canvas texts, there's usually no more than hundred of them.

    Unity 2018.3.2f1
     
  4. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    20
    I was able to "optimize" it by using this inherited class instead

    Code (CSharp):
    1. public class TextMeshProFast : TMPro.TextMeshPro
    2. {
    3.     private void LateUpdate()
    4.     {
    5.         // This is defined to disable private LateUpdate in base class
    6.         // Base class implementation detects scale changes and updates text
    7.         // It takes 0.64ms for 1530 instances
    8.     }
    9. }
    10.  
    Attached profiler screenshot, this 'hack' is about 5-6x faster (measure in build)

    EDIT:
    After changing all instances to TextMeshProFast, it takes 0.12ms, that's 5.33x improvement
     

    Attached Files:

    Last edited: Jan 25, 2019
    justtime likes this.
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    2,633
    I have replaced the use of LateUpdate in the next release of TMP for a manager which should provide some improvements. I'll re-run some benchmarks and provide results thereafter.

    In terms of your hack just be mindful that LateUpdate is mostly used to account for scaling changes on the text object. Provided the scale of your text object will not change, your teak should be fine :)