Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro WebGL + TextMesh Pro (1.3)

Discussion in 'UGUI & TextMesh Pro' started by tcvpromo, Oct 4, 2018.

  1. tcvpromo

    tcvpromo

    Joined:
    Jun 7, 2017
    Posts:
    25
    we have been looking at textmesh pro for a long time to replace unity UI text.
    And we decided to make a benchmark to compare:
    - webgl build size;
    - memory consumption (very important for webgl);
    - performance;

    Tests were carried out in an empty new project, where:
    - Unity ver. 2018.2.4f1
    - strip engine turned on;
    - memory allocation = 80mb
    - No extra packages included
    - TMpro used 1 material, atlas 512x512

    What we got when comparing:
    1. 300 text components on scene (just white text with no effects):
    - build with TMpro wasm takes 200kb more than unity UI text (this is the same in all comparisons of course. And this is really important). Here we had to comment out the line where physics is used in the TMpro sources, since in our project it is not used. We also left only 1 shader and deleted all unnecessary unused ones.
    - TMpro uses much more memory. The empty project in both cases uses 36mb. TMpro + 300 text components = 55mb, when unity UI text = 44mb (11 MB difference).
    - The performance is about the same in both cases.

    2. 30 text components on scene (simple white text with no effects):
    - TMpro = 39 mb of memory, when unity UI text = 36 mb (difference 3 mb)

    Questions (can anyone working with TMpro in the webgl and have encountered this problem):
    1. How can I minimize the additional increase in the size of the build when using TMpro?
    2. Why such a big difference in memory consumption? Maybe there are some tips?
    3. Using TMpro will add additional draw calls due to the fact that for each effect you need to make your own material for the text (for example, just text, text with a shadow and text with the outline of a certain color). Has anyone compared performance in this way? For example, 50 text objects, where every 10 has its own material and, accordingly, in TMpro it will be 5 draw calls, when there is only 1 in the UI test unity.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    In terms of build size, I would have to take another look at this. You do appear to have stripped the additional shaders, etc. Also look at whether or not sprite assets or other resources were still included in that build. Make sure the Examples & Extras were removed.

    The data structures used by TextMesh Pro have a larger memory footprint which for the most part is necessary to enable a lot of its functionality. Having said that there are certainly a few things that I will / have been working on to improve on this.

    With regards to draw calls, provide all text objects use the same material preset, there should be no difference between UI.Text and TMP UGUI text objects in terms of draw calls. Now if you end up using multiple materials or fonts or using the fallback or sprite then it is one draw call per material used but these batch between each other.

    Although displaying a text object with plain white text + another text object with outline and shadow will result in two draw calls (since you are using two materials), it still yields significantly better performance than using the UI - Effect - Outline and Shadow scripts which will increase the geometry count by 5x or greater and crushing performance on some mobile devices. See this old post of mine about this.

    Draw calls used to be a big issue back in the early iPhone days but that's no longer really the case as most devices can chew through a lot of draw calls these days. On most devices, you can't really see any difference between 1, 10 or even 50 or more draw calls. On some devices batching is more costly than the draw calls. Obviously you still want to be efficient but whether these 300 text objects result in 1, 5 or even 20 draw calls that impact will be marginal and fill rate will be more of an issue.

    P.S. Reducing build size, memory foot print and improving performance wherever I can is most certainly important while continue to increase functionality.
     
  3. tcvpromo

    tcvpromo

    Joined:
    Jun 7, 2017
    Posts:
    25
    Thanks for the answer.
    We made some more benchmarks and got:
    1. The problem with memory consumption is not related to TMpro. This is some kind of bug in unity, when it can sometimes consume 10mb more than usual in an empty project.
    2. The final difference in size between an empty project with utext and an empty project with TMpro + IMGUI was 413kb (2801kb vs. 2388kb. WASM).

    Are there any plans to get rid of the IMGUI module? In WebGL, every 100kb is very important ...