Search Unity

Question UI Toolkit is using a lot more vertices than UGUI

Discussion in 'UI Toolkit' started by anidiot, Sep 23, 2021.

  1. anidiot

    anidiot

    Joined:
    Sep 19, 2020
    Posts:
    2
    Hi, while I was comparing performance between a UI Toolkit ui and a UGUI ui, I find that it seems like UI Toolkit is using way more vertices to render a ui (especially when there are texts in the ui) than UGUI.
    I recreated a UI from a game I had (which was built with UGUI and uses around 2k verts) using UI Toolkit with the same sprites and font, and it uses around 23k verts.

    When I tried to strip down my UI to find out which element is the cause, I realized that the vertex count of UI Toolkit is very "unstable", meaning that it can vary a lot with a smallest change (like 1px wider).
    Please check attachments for examples.

    so I think my questions are:
    1. Are these expected behaviours?
    2. Should I be worry about the vertex count?
    3. And why is UI Toolkit using 10 times of verts UGUI uses? Did I do something wrong? maybe missing some configurations?
     

    Attached Files:

  2. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,000
    Hello!

    It is expected that UI Toolkit will generate more vertices. UGUI mostly handles textured quads, which are quite cheap in terms of vertices. UI Toolkit generates vector shapes, which require more tessellation. That being said, the vertex count shown in your screenshots seems higher than what I would expect. Also, such variance with a 1px difference is very odd, so we'll make sure to investigate that.

    Thanks for reporting!
     
    anidiot likes this.
  3. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    I just stumbled onto this thread and after reading this sentence, decided to check out the performance of my UI. Well, there seem to be more issues with vertex count, especially during animations, as an example, here is a video:



    The only thing I'm changing is the size and color of the image (VisualElement). During the animation, vertex count peaks at over 150K, and after it, I get additional 1K vertexes. This sounds like a lot for a small icon.

    And when I'm triggering other, more complex animations, I get spikes from 50K to even 600K vertexes:



    I don't feel like I get all of these numbers only because I'm rendering hundreds of frames per second. It's either single VisualElement have way more vertexes than needed or something unnecessary also gets redrawn. Is there any way to debug what is redrawing at the moment?

    Also If you look at the video above, by hovering over the images the amount of batches increases? Seems a bit weird even though as far as I remember, some person from the unity team claimed that this number isn't accurate in SRPs/ URP so Idk.


    Also, one more thing. When I'm hovering over the buttons at the bottom, I get 6-7ms spikes for no reason, here is a screenshot from the profiler:

    profiler horror.JPG

    That doesn't feel normal. Especially since I haven't even started scripting this UI. Is this a known issue?
     
  4. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,000
    There are a few things to consider.

    When an element requires a repaint (which happens often during a transition animation), the newly generated element won't immediately override the previous one in the vertex buffer. It will be allocated in a temporary location for a few frames until we are sure it is safe to override the original element. So it is expected to have a larger amount of active triangles during this process. We keep the geometry alive for at least 4 frames if my memory serves me well, so this may explain why we see the triangle count jump in your example.

    However, as I mentioned earlier, these counts seem much larger than what is expected. This will be investigated.

    Your sample project seems very good to reproduce this issue. Is there any chance you can share it with us?
     
  5. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    Sure, I have reported this as a bug: Case 1368422


    Also, I've decided to make two more bug reports since I haven't got any response about:
    • hovering over two specific buttons causes 6-7ms spikes: Case 1368428
    • amount of batches and vertexes drastically increases after stopping hovering over animated buttons: Case 1368424
     
    anidiot likes this.
  6. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,000
    Thank you!
     
  7. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    89
    I also noticed this problem,the sample project is below. Run sample scene, when there is no animation, the vertices number is 7K,but when i shake the visualElement using Dotween,the number increased sharply.
    Is this a bug??

    upload_2021-10-19_17-38-57.png
     

    Attached Files:

    Last edited: Oct 19, 2021
  8. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    It is a bug, I've reported it already, and it landed on the issue tracker. Here is a link, you can vote for the issue so hopefully, it will be fixed a bit faster:
    https://issuetracker.unity3d.com/is...ncreases-when-hoovering-over-animated-buttons.

    And btw, you don't even need to modify the size, shape, or position of the Visual Element. You can change the color of the VisualElement and you still will see spikes of vertexes.