Search Unity

Unity2018.4.2f1 x 1.5.0 , TryAddCharacters(string characters) very slow. when a lot of characters

Discussion in 'UGUI & TextMesh Pro' started by tim12332000, Aug 14, 2020.

  1. tim12332000

    tim12332000

    Joined:
    Jun 15, 2017
    Posts:
    20
    I test TryAddCharacters(string characters) this api , and here is my code:

    //TestStr3000 = 3000 chinese word.
    tmp.TryAddCharacters(TestStr3000);
    And my settings:
    upload_2020-8-14_11-43-54.png
    Here profiler
    upload_2020-8-14_11-41-20.png

    I also test all Atlas Render Mode , All of than is slower. Can I fix it ?
    I also test 200 chinese word , it also need 170ms in mobile.

    And I test "TextMesh" UnityEngine.Font it is very faster to create texture , how he did it ?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The SDF render modes like SDFAA refers to Signed Distance Field.

    Computing the Signed Distance Field to add glyphs a texture is substantially more computational intensive then simply adding bitmap glyphs to a texture.

    As such, users should be using static font asset that contain all the known text used in the project for any given language or groups of languages and dynamic font asset for the unknown text which is typically coming from user input.

    Although adding SDF generation at runtime has significant overhead, it is still substantially faster than any human can type where as such, the added performance overhead will not be noticeable to any users.

    Please watch the following videos which explains most of this and the recommended workflow to handle languages such as CJK.



     
  3. tim12332000

    tim12332000

    Joined:
    Jun 15, 2017
    Posts:
    20
    Yes , but my case is a lot of userName , It showing at runtime, So it's not a single inputbox at this case . by the way
    I am interested in "SDFAA" How it calculation , can you post some link let me know it or get me some keyword . thanks.:):)
     
    Mihalchev likes this.
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Since users (humans) usually type one character at a time, it would be unlikely for more than one character and glyph to need to be added to the atlas texture at once. As such, the performance overhead would not be an issue.

    Again, if you primary font assets contain all the known text in your menus, UI, dialogue, etc. then all the dynamic system has to handle is user input which again should be fine. What you want to avoid and should not do is rely on the dynamic system for all the known text.

    The only time someone would rely on the dynamic system for all the known text would be when using OS fonts but even then you could add all the needed character while loading your scene as opposed to when the text needed to be displayed.

    No links as this is my own implementation using a mixture of 3x3 EDT scanning combined with anti aliased sdf.
     
    tim12332000 likes this.