Search Unity

VisualElement with radius borders are very slow

Discussion in 'UI Toolkit' started by Cripplette, Aug 18, 2021.

  1. Cripplette

    Cripplette

    Joined:
    Sep 18, 2012
    Posts:
    66
    Hi,

    I have identified a performance issue with VisualElements that have a border with a radius >0.
    When you have a lot of elements within a ListView, the scrolling is really slow in this case.

    In the first screen I have disabled the radius property of each VisualElement : scrolling is really smooth and nothing special on the profiler.

    upload_2021-8-18_10-15-21.png

    On the second screen there is a radius of 5 for each border of the VisualElement : scrolling is really slow and profiler show really long time spent in the RenderChain

    upload_2021-8-18_10-15-32.png
     
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    Hi, the tessellation of rounded corners is indeed fairly costly at the moment.

    Would you mind sharing roughly what happens inside the bindItem callback for the ListView ?

    In some cases there might be some saving that are possible by preserving more of the existing element.
     
  3. Cripplette

    Cripplette

    Joined:
    Sep 18, 2012
    Posts:
    66
    The bindItem method is empty, i was only testing static content to understand why my lists were so slow.
    It looks like that it recalculates the rectangle for every object while you scroll the list, but the layout/items should not be updated right ?
     
  4. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    After looking at why this would happen we have identified a potential performance improvement. Since you seem to have a good reproduction use case window, would you mind logging a bug from Unity?

    Currently this happens because elements are removed and re-added at a different index in the ListView.
    We can most likely hold on to the generated meshes and avoid re-doing the tessellation step again.
     
  5. Cripplette

    Cripplette

    Joined:
    Sep 18, 2012
    Posts:
    66
    You could also try to re assign a cell to the same VisualElement in order to avoid the binding and recalculating of everything and saves a lot of processing power.