Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Very first LocalizeStringEvent invocation is very slow

Discussion in 'Localization Tools' started by emredesu, Jun 2, 2023.

  1. emredesu

    emredesu

    Joined:
    Aug 12, 2021
    Posts:
    51
    Hey! I was inspecting the cause of a framedrop caused especially on low-end devices, and upon inspections with the profiler, I noticed that the reason is the LocalizeStringEvent component doing a localization for the very first time.

    upload_2023-6-2_21-51-56.png

    Is it possible to do something to prepare the localization system in the loading screen in order to avoid this framedrop?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
  3. emredesu

    emredesu

    Joined:
    Aug 12, 2021
    Posts:
    51
    I'm not using WaitForCompletion, only the LocalizeStringEvent component - I don't know if that does that internally.

    The preloading is already activated, doesn't seem to help :(
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    You can try yielding on LocalizationEditorSettings.InitalizationSettings during the start of your application. This will perform the preloading
     
  5. emredesu

    emredesu

    Joined:
    Aug 12, 2021
    Posts:
    51
    I just tried putting

    yield return LocalizationEditorSettings.InitalizationSettings;


    before loading the first scene in the application's very first loading screen, but that first freeze-up still persists...
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    Can you see what the freeze is coming from? What is happening in OnEnable sub calls?
     
  7. emredesu

    emredesu

    Joined:
    Aug 12, 2021
    Posts:
    51
    Seems like it boils down to Mono.JIT at the end, after which the load spreads out among internal Mono functions like GC.Alloc.
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    Can you share a screenshot of the breakdown?
    Or the profile capture file
    It's also worth trying the addressables event profiler to see what is being loaded at that time, it should be nothing.
     
  9. emredesu

    emredesu

    Joined:
    Aug 12, 2021
    Posts:
    51
    Sure thing, here is the screenshot; upload_2023-6-4_23-23-16.png

    and here is the profiler capture file:
    https://drive.google.com/file/d/1k_TtBlXXrkaEAPEMZ3HiEp7KX85sIXWC/view?usp=sharing

    The lag spike occurs on frame 204/300 (should be obvious on the graph) :D
     
  10. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    The profiler capture doesn't show any asset loading so it looks like the preloading is working, was this with a deep profile? It looks like it may be coming from the Smart String system creating its pools, are you using a smart string, what does it look like?
     
  11. emredesu

    emredesu

    Joined:
    Aug 12, 2021
    Posts:
    51
    No, I forgot about the deep capture feature :(

    I'm using many smart strings in this project indeed. The one that caused the lag in this instance looks like this:

    {interactKeyName} - Open Chest - <color=#26ABFF>{normalGoldCost}</color><sprite name=coin> 


    interactKeyName - StringVariable
    normalGoldCost - IntVariable

    Though this happens with other Smart Strings if they are created for the first time as well. Is there a way to have the Smart Strings create their pools during the loading screen?
     
  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    You could call Smart.Format with a similar string as above, this would create most of the pooled objects. You can do this anytime, its not dependent on the localization system.
     
  13. emredesu

    emredesu

    Joined:
    Aug 12, 2021
    Posts:
    51
    I couldn't figure out how to use Smart.Format (it kept throwing exceptions), so I decided to add a LocalizeStringEvent with Local Variables in my loading scene for an off-screen text to achieve the same effect and voila - the lag caused by smart formatting is gone!

    upload_2023-6-6_21-2-54.png


    Upon further inspection I found out that most of the lag was actually caused by -this- very first TextMeshPro call... However, thank you for your help, shaving off a 20ms is a good achievement too! :D

    upload_2023-6-6_21-41-0.png
     
    Last edited: Jun 6, 2023
    karl_jones likes this.