Search Unity

TextMesh Pro Speed Problem

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by unity_P6mxp0LUvUdvoA, Jun 13, 2019.

  1. unity_P6mxp0LUvUdvoA

    unity_P6mxp0LUvUdvoA

    Joined:
    Sep 11, 2018
    Posts:
    5
    Hello,

    I just recently converted our product to use TextMesh Pro, and am noticing some significant UI slowdowns, particularly in our chat window, which is optionally shown and hidden by clicking a button. When profiling, I noticed that the problem is that TextMeshProUGUI components have an OnEnable call, and we have multiple text components for each chat message. The OnEnable calls seem to take .32ms each, which can add up quite quickly. Is there any way to avoid the expense of the OnEnable call or just remove the call altogether?

    See image for what we're seeing.
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,340
    Make sure you are testing in a build as there is additional overhead in the Editor.

    Enabling / Disabling UI objects that are using Layout Components or affected by Layout components will trigger a rebuild of the layout which has performance overhead.

    In order to provide additional insight, I would need a better understanding of the hierarchy of these scene objects and if they are affected by Layout components.
     
  3. unity_P6mxp0LUvUdvoA

    unity_P6mxp0LUvUdvoA

    Joined:
    Sep 11, 2018
    Posts:
    5
    Hello,

    I was able to get more detailed information using the deep profiler. It seems that TMP_Text.ParseInputText took 113ms to rerender its canvas, which is really expensive. Seems like most of the time is spent loading the font using FontEngine.LoadFontFace(43ms), which is crazy to have to call every time we disable->enable a script object.

    Please see the attached deep profiling session.
     

    Attached Files:

  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,340
    This specific performance issue has already been addressed. See the following post for more details. The changes will be included in the next release of the TMP package which will be version 1.4.2 for Unity 2018.4 and 2.0.2 for Unity 2019.x.
     
  5. unity_P6mxp0LUvUdvoA

    unity_P6mxp0LUvUdvoA

    Joined:
    Sep 11, 2018
    Posts:
    5
    Awesome, thanks. Is there any way around this for now, or an eta on the next release? Hoping to get a fix for this soon.
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,340
    Making the following changes to the TMP_FontAsset.cs will help but is only part of the changes.

    upload_2019-6-13_16-11-29.png

    This change will make it so that TMP doesn't try to add a character / glyph that is already known to be missing. This should help.

    In terms of the next release, maybe within the next 10 days. I need to get the core changes to land in Unity first since the changes to the FontEngine are in Unity itself and not the TMP package.
     
  7. unity_P6mxp0LUvUdvoA

    unity_P6mxp0LUvUdvoA

    Joined:
    Sep 11, 2018
    Posts:
    5
    Thank you so much! That's exactly what I was looking for. Will be looking forward to the update in 10 days.

    I had one more quick question: Do you have any plans to make default dynamic fallback fonts from the system fonts from the fonts returned from Font.GetOSInstalledFontNames? I know it's not currently possible because we can't get the font file paths from that call, but was wondering if you could just have those be the default fallback internally somehow?

    Thanks!
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,340
    Short answer Yes.

    However, it will be implemented using the following new function.

    Code (csharp):
    1.  
    2. // Get the file path of all OS fonts.
    3. string[] fontPaths = Font.GetPathsToOSFonts();
    4.  
    5. // Create new Font using one of those paths.
    6. Font osFont = new Font(fontPaths[124]);
    7.  
    8. // Create new font asset using this OS font.
    9. TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(osFont);
    10.  
    11.