Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug EditorResources.styleCatalog has very high assembly reload cost

Discussion in '2020.1 Beta' started by SugoiDev, Oct 25, 2019.

  1. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    I just noticed the initialization of EditorResources.styleCatalog costs between 1.4 and 2s of my <5s assembly reload times. Tested on the latest alpha 2020.1.0a9.

    It seems most of the cost comes from string operations.

    upload_2019-10-25_12-44-27.png
     
  2. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Hi, do you have any custom uss files in your project that could explain these load times? If you do, can you share them with me and I'll make sure this gets optimized.

    Thanks,
     
  3. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    I don't has any custom uss around, and I see similar (but lower) times on empty projects. I have 2D Sprite, QuickSearch and TextMesh Pro packages.

    The cost seems to come all from string operations and heavy usage of IndexOf on lists. For the IndexOf hit, maybe it should use a better structure during data generation, so it won't call IndexOf so many times. Then use ToList or similar when done, if an actual List is required.


    If I have the time later, I'll read the code and see if I can understand what is happening a bit better.
    Thanks for the reply.
     
  4. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    I have an upcoming performance fix for this issue. I'll let you know when it will be available for testing in the Hub.
     
    SugoiDev and Peter77 like this.
  5. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Just tested on a14 and the issue seems to still be there.

    upload_2019-11-25_19-36-39.png
     
  6. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    The optimization is not in yet. Here's a preview of the numbers you should get:

    High level performance tracker:

    upload_2019-11-25_22-3-23.png

    Deep Profile trace:

    upload_2019-11-25_22-4-24.png
     
    SugoiDev likes this.
  7. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Compared to this (without the optimization):

    upload_2019-11-25_22-16-35.png

    So now ExpandValues should scale much better with the increasing number of extended styles and it should take much less memory too.
     
    SugoiDev likes this.
  8. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Also without the optim, here's the high level perf. trackers:

    upload_2019-11-25_22-18-29.png
     
    SugoiDev likes this.
  9. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Oh wow, those look great!

    Is that Performance tracker available somewhere? Seems pretty useful.
     
    jonathans42 likes this.
  10. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    The package is still internal, but if should be usable (latest 2020.1 only).

    You can drop the package as an embedded package. Then the window will be available through:

    upload_2019-11-25_22-28-36.png

    Then you should see all the available perf trackers:

    upload_2019-11-25_22-29-27.png

    Unfortunately, the API to add new performance trackers is still internal, but if you have access to internal API you can do something like this to add new ones:

    Code (CSharp):
    1. using (new EditorPerformanceTracker("Tracker.PerformNotifications"))
    2. {
    3.     PerformNotifications(now, trackerNames);
    4. }
    Full API looks like this:

    Code (CSharp):
    1. internal struct EditorPerformanceTracker
    2. {
    3.     public static extern string[] GetAvailableTrackers();
    4.     public static extern bool Exists(string trackerName);
    5.     public static extern void Reset(string trackerName);
    6.     public static extern int GetSampleCount(string trackerName);
    7.     public static extern double GetLastTime(string trackerName);
    8.     public static extern double GetPeakTime(string trackerName);
    9.     public static extern double GetAverageTime(string trackerName);
    10.     public static extern double GetTotalTime(string trackerName);
    11.     public static extern double GetTotalUsage(string trackerName);
    12.     public static extern double GetTimestamp(string trackerName);
    13.     public static extern void LogCallstack(string trackerName);
    14.     public static extern void GetCallstack(string trackerName, Action<string> onCallstackCaptured);
    15.  
    16.     internal static extern int StartTracker(string trackerName);
    17.     internal static extern void StopTracker(int trackerToken);
    18. }
     

    Attached Files:

    SugoiDev likes this.
  11. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Awesome.
    It's working nicely (only had to deleted te Tests because some were broken).

    This is a very useful package. Thank you!
     
    jonathans42 likes this.
  12. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Just saw the changelog for a15.
    Did a quick test today and StyleCatalog.Load is down from ~1.4s to ~0.83
    Still taking quite a bit of time, but better than before!

    upload_2019-12-13_12-55-53.png


    I also noticed some new UIElements things, taking quite a bit of time now.
    Examples: Toolbar.OnEnable (taking almost 600ms).
    Any idea if this is being tracked? Should I submit a report?

    upload_2019-12-13_12-56-12.png
     
    Peter77 likes this.
  13. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Wait for the next release, now the style catalog is being serialized and reloaded from disk for all subsequent domain reload, so when entering play mode, reloading the style catalog shouldn't take more than 30-50 ms.
     
    SugoiDev likes this.
  14. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Oh, that's some awesome news!

    I'll keep an eye out for it. I'll wait until the next alpha to see if the Toolbar.OnEnable hit is still there too.
    Thanks for keeping us posted!
     
  15. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    I completely forgot about this thread, so the performance improvements should have worked. Thanks!

    Incidentally, did the performance tracking package ever get released or is it still internal only? It's a great tool!
    I remembered this thread because I was reading the editor.log today after a crash and noticed lots of detailed [Performance] information. Pretty cool.

    upload_2020-2-29_1-56-55.png
     
  16. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    We will release it on https://github.com/unity-technologies in the upcoming weeks.

    Thanks for the feedback
     
    SugoiDev likes this.
  17. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    SugoiDev and Kirsche like this.