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 Assembly reload performance degradation due to boxing in StyleCatalog.SetIndex<T>

Discussion in '2019.3 Beta' started by SugoiDev, Aug 3, 2019.

  1. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Submitting a bug report for this one is a bit hard, so I'm posting it here as a heads up.

    UnityEditor.StyleSheets.StyleCatalog.SetIndex<T> cost about 25% of my assembly reload time (total of about 14s while deep profiling).

    screenshot 2019.08.03-04.08.59.png

    All this cost is coming from the IndexOf in the generic list.
    That is about 3.4s (of which 2.2 are just due to garbage collection due to the default equality comparer being used in value types). It also costs 75MB of allocations (from a total of about 190MB) due to this heavy boxing.

    It would probably help to have non-generic overloads (or force T to have IEquatable<> implemented).
    Since this is called many times, the times are adding up fast.

    This is a low hanging fruit with quite impressive gains if optimized.
     
  2. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    Thank you for spotting it!
    The fix which implements IEquatable<> for StyleCatalog structs is on the way to 2019.3
     
    Grizmu, SugoiDev and jonathans42 like this.
  3. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Thanks for reporting SugoiDev, the timing was good, we fixed that issue a few days ago.
     
    alexeyzakharov and SugoiDev like this.
  4. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Incredible!
    I was baffled to see such a delicious fruit hanging, but I guess I was too late to notice and it had already been picked (and eaten).

    Thanks for keeping us posted!