Search Unity

[5.2] Terrible performance spike causing by Font cache

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by BenouKat, Sep 9, 2015.

  1. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    I keep this thread up to date, in case of someone else have this bug issue : The problem still appears on 5.2.2p3.
    (I noticed in 5.2.2p3 a LogStringToConsole line which takes some times too. Don't you forget to remove one of your debug log guys ?)

    BUT our studio was forced to move on 5.2, because we absolutly need asset bundle manager. So, I spent some times to find a solution for these huge freeze aaaand I found one.

    I put Text component with every font I use in my game with every caracters of my keyboard, set best fit from 0 to 100 size, I displayed them on splash screen, first scene on first frame and tada! No problem. Because I think Unity put them on cache and my UI doesn't freeze any more.
    Some UI will freeze, may be I miss some special caracters, so I simply display the UI on splash too with the other fonts, and it works.

    So it's a dirty fix but Unity team, even if they are doing their best, aren't fix this problem yet and this is the only solution I found so far.
     
  2. alesm-o7

    alesm-o7

    Joined:
    Sep 30, 2015
    Posts:
    3
    This was certainly introduced in 5.2, because I just did a profile on an Android device that our QA played for some time. When I started profile, I started a new match (in the same app session) and Font.CacheFontForText calls was ~35000, and after another match it was ~70000 calls(!!!!) - this is all in the same app session. But when I restarted the app and started a new match it was like ~60 calls.

    I tried going back to 5.1.4f1 and this bug was completely gone and overall performance was MUCH better.
    I'm currently in the process checking this on 5.3.0b5 but thanks to cache server/assets not being compatible any more it takes a lot of time to build.

    Regards,
    Ales
     
  3. phasiclabs

    phasiclabs

    Joined:
    Nov 13, 2013
    Posts:
    126
    I'd just like to add my my request that this is fixed ASAP - it's causing us real problems now, and we are approaching our beta date. We can't really roll back as we need other fixes from recent patches. I just raised a bug about this (742562) before I spotted this thread.
     
  4. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    @phasiclabs same situation for us, you can use the trick that I used at the top of this page if you want, it works great.

    Not optimal but it's better than these terrible freezes.
     
  5. Jakhongir

    Jakhongir

    Joined:
    May 12, 2015
    Posts:
    37
    Putting UI before first scene worked for me.
     
  6. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    Yep, and you can put a Canvas Group component with alpha at zero and it becomes invisible.
     
  7. shibasaki

    shibasaki

    Joined:
    Feb 12, 2015
    Posts:
    12
    We are also having same problem. Can't use pre-cache workaround because our game uses many non-ascii characters. Hope this bug fixes ASAP
     

    Attached Files:

  8. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,153
    So as i dont think we've given a update recently the hold up getting this fix into a 5.2 release is due to the fix not being able to land in our main company wide repo just yet so the backport team is holding off (makes sure one fix doesn't show up in a backport but never in a future release). Hopefully in a couple days the fix will land in both the backport branch and the main branch
     
    Jakhongir, BenouKat and Dantus like this.
  9. VictorCashDaShi

    VictorCashDaShi

    Joined:
    Nov 13, 2015
    Posts:
    30
    I had same problem with Font.InvoikeTextureRebuilt_internal()
    Try to select your font file and set the Rendering Mode to OS Default or disable the dynamic
    it will solve the problem
     
    Last edited: Nov 13, 2015
  10. phasiclabs

    phasiclabs

    Joined:
    Nov 13, 2013
    Posts:
    126
    Did this fix make it into the new 5.2.2 p4 patch? It's not mentioned in the fixes list...
     
  11. phasiclabs

    phasiclabs

    Joined:
    Nov 13, 2013
    Posts:
    126
  12. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    I can confirm it's still here, and more than that : I don't see any line in the Unity 5.3 related to this issue. So i'm afraid the wait will be longer...

    I created the issue linked above and it's not fixed at all.
     
    Last edited: Nov 16, 2015
  13. NoseKills

    NoseKills

    Joined:
    Jun 4, 2013
    Posts:
    25
    Judging from what phil-Unity said, could be just a matter of process: the issue might be fixed in a branch that was supposed to be merged into some version of 5.2.2 and so the bug was marked fixed... but the fix just hasn't found its way into an actual build yet.

    Just guessing though.
     
  14. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,153
    Yea its as NoseKills said it just hasn't made it way to a released build yet. Dont worry i'm still following up on this to make sure it gets in.
     
  15. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    Okay thanks to update us phil :) !
     
  16. Jakhongir

    Jakhongir

    Joined:
    May 12, 2015
    Posts:
    37
    Has anyone tried new 5.2.3 version, has the problem been solved there?
     
  17. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    265
    My project runs into several errors in 5.2.3 on ios, works fine in prev version. Deleted it rightaway
     
  18. swyckoff

    swyckoff

    Joined:
    Apr 18, 2015
    Posts:
    1
    Problem appears to still exist in 5.2.3. We were able to work around it by using BenouKat's pre-cacher idea and changing our fonts to ASCII default. Hopefully that gets us through until Unity can push the fix through.
     
  19. pfreese

    pfreese

    Unity Technologies

    Joined:
    Feb 23, 2015
    Posts:
    85
    I just received notification that this fix has been (finally) merged into our 5.2 branch and should be in the next patch. Sorry for the delay.
     
  20. shibasaki

    shibasaki

    Joined:
    Feb 12, 2015
    Posts:
    12
    Is there any ETA on next patch?
     
  21. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    They release a patch almost every week or couple of week at this point, so soon I hope :)
     
  22. artem101

    artem101

    Joined:
    Sep 20, 2013
    Posts:
    3
    They mentioned it as fixed in 5.2.3p1 changelog, but it looks to me the problem is still there.
    Can someone check it out?
     
  23. TitanUnity

    TitanUnity

    Joined:
    May 15, 2014
    Posts:
    180
    Yea, problem still exists in 5.2.3p1 from what I can tell.
     
  24. TitanUnity

    TitanUnity

    Joined:
    May 15, 2014
    Posts:
    180
    To add a little more detail, I've installed 5.2.3p1, ran our app in both the editor and on the device and we see massive spikes like this one, typically when new text is displayed on the screen. FontCache.PNG
     
  25. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    I just received a mail from Unity QA and the bug seems to be fixed in 5.2.3p2 .... which is not available yet.

    I'm going to ask if it's a typo (and in this case the bug is still here), or if it's really in the patch 2.

    I keep you in touch guys :)
     
    Jakhongir likes this.
  26. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    Ok I just got the answer : The bug is fixed in 5.2.3p2 and not p1. It'll be available "very soon".

    If some of you guys are still have problems with the patch 2, please leave a message here, I'll update the issue to the QA. (Personally I can't change the version of my Unity for now, I'll do it soon).
     
  27. TitanUnity

    TitanUnity

    Joined:
    May 15, 2014
    Posts:
    180
    Whew, this is awesome news, looking forward to the patch. Thanks for the update on this.
     
  28. TitanUnity

    TitanUnity

    Joined:
    May 15, 2014
    Posts:
    180
    5.2.3p2 just released! Going to install and try again!
     
  29. TitanUnity

    TitanUnity

    Joined:
    May 15, 2014
    Posts:
    180
    Hey good news, with 5.2.3p2 so far it looks like our issues with Font.CacheFontForText are gone. Will continue testing, but so far so good!
     
  30. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    Awesome news :D Thanks you !

    Can someone else confirm it's gone ? I'll update the thread main page / title.
     
  31. engelcj

    engelcj

    Joined:
    May 20, 2014
    Posts:
    122
    Hey I have the version 5.2.3p2 and yet I have the problem.
     
  32. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    Weird, I got the version and the problem is fixed. My cache is below 1.9Mo GC Alloc vs 300 Mo before, and takes "only" 400ms to display all my fonts.
     
  33. Knskan3

    Knskan3

    Joined:
    Sep 1, 2014
    Posts:
    19
    I just updated to 5.3 and the issue is still there. Some times when I update a custom from text, in this case the scorer, best fitted the Font.CacheFontForText strikes back with 315ms.

    Any help?
     
  34. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    Can you post a screenshot ? Because Font.CacheFontForText always takes a while. Before the first scene I render all my characters of all my police, and CacheFontForText is 450ms.

    But this is not the bug previous version of Unity, the bug was a spike to 3 or 4 seconds and 300Mo of GC.
     
  35. engelcj

    engelcj

    Joined:
    May 20, 2014
    Posts:
    122
    I updated to the version 5.3 and still the problem is there.
    Captura de pantalla 2015-12-09 a las 7.40.27 a.m..png
     
  36. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    As I said, the bug was 3 second freeze, 9000 calls and 300Mo GC Alloc. So this is a different problem.
     
  37. engelcj

    engelcj

    Joined:
    May 20, 2014
    Posts:
    122
    Ok thanks i will do the report of this problem.
     
  38. artem101

    artem101

    Joined:
    Sep 20, 2013
    Posts:
    3
    I can also confirm the problem is still there - about 5 seconds delay on first run, without data in windows cache.
    However, I am not sure if it is the same problem.
    Besides, shouldn't this problem be mentioned as fixed in 5.3 changelog?
    It would be great to get confirmation from unity team that the issue is fixed in 5.3.
     
  39. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    Can you attach screenshot of the profiler, ti see if it's the same bug ? If it is, I will remove the resolved tag
     
  40. artem101

    artem101

    Joined:
    Sep 20, 2013
    Posts:
    3
    It may be a different problem, after all.
    delay2.jpg
     
    Last edited: Dec 10, 2015
  41. engelcj

    engelcj

    Joined:
    May 20, 2014
    Posts:
    122
    I have solved my problem, what I've done is choose import settings from my font in the option Character "Custom Set" instead of "Dynamic" and I have written all the letters and numbers that I need, also within the same configuration, I have put the size at 175 and have applied and now not gives me more spikes. This configuration might not be adequate but I have solved my problem.
     
  42. Jakhongir

    Jakhongir

    Joined:
    May 12, 2015
    Posts:
    37
    Yeah, I am doing the same thing in my project. But the problem is that "best fit" is only supported for dynamic fonts.
     
  43. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    218
    Hm it's weird, it look like similar but not exactly the same. I remove the resolved tag.
     
  44. engelcj

    engelcj

    Joined:
    May 20, 2014
    Posts:
    122
    Yes, exactly that's a problem, but temporarily in my canvas scaler I set a reference resolution and don't need use the "best fist" in the text. Is not perfect but works for me.
     
  45. NoseKills

    NoseKills

    Joined:
    Jun 4, 2013
    Posts:
    25
    They are working on so many branches and versions at the same time it's a bit hard to keep track which fixes make it to which version. I guess the fix for the spike bug in 5.2.3p2 didn't make it to 5.3 yet

    Unity 5.2.3p2
    • (735927) - UI: Fixed a performance issue with fonts rebuilding.
    Unity 5.3 beta RC1
    • Fixed issue that caused FontUpdateTracker to add an additional RebuildForFont handler whenever a Text component was enabled using a font with no other active Text components using that font.
    The first bug is the relevant one i guess. The second sounds like it could be related but i guess not since people are having these spikes in 5.3 still.
     
  46. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    27
  47. pfreese

    pfreese

    Unity Technologies

    Joined:
    Feb 23, 2015
    Posts:
    85
    The number of calls to CacheFontForText seems reasonable in that screenshot, so it's a different problem than that being described earlier in this thread. Can you provide a bit more information about the platform you are seeing this issue on, and anything about the font, size, style, and text being drawn? Ideally a bug report with a minimal repo project will help us look into this.
     
    DannyHellfish likes this.
  48. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    27
    Hey, thanks for the reply. Platform is iOS/iPad 3, Font is source sans pro, Font Size text label is 52, best fit is off, Text is a headline (something like 25 latin chars in this case ), scale is 1.

    Font settings are 52, smooth, fast ascender metric, including font data = true.

    Can't switch off dynamic fonts as we support lot of asian/non-latin languages. The same font is used for a lot of other text labels but the 52 sized label is the only one which spikes in these extremes.

    Canvas settings are Screen Space - Camera and scale with screen size.

    I even create a string at the start of the game and RequestCharactersInTexture but it doesn't help. Still get these random spikes due to CacheFontForText.

    Will see if I find the time to make a repo project.

    Thanks for helping.
     
  49. pfreese

    pfreese

    Unity Technologies

    Joined:
    Feb 23, 2015
    Posts:
    85
    Do you see the perf issues only on the iPad, or running in the editor as well? It would be useful to isolate whether this is an iOS specific issue.
     
  50. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    27
    Only on the iPad.

    After hacking around for a while I found a really really S***ty hack to make it work. I now have a transparent label on the screen at all times with all used chars for the current loca. That's the only way I've found to prohibit Unity from using CacheFontForText.
     
    Last edited: Jun 28, 2016