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

Feedback (Case 1420752) RectTransform.rect very expensive

Discussion in '2022.2 Beta' started by Peter77, Apr 17, 2022.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Accessing the
    .rect
    property of a
    RectTransform
    is very expensive compared to other operations.



    On an AMD Ryzen 3900 it costs:
    • Accessing RectTransform.rect 1000 times cost 2ms :eek:
    • Accessing RectTransform.localToWorldMatrix 1000 times cost 0.6ms

    The RectTransform.rect property is used across a lot of Unity UI code. I believe the overall UI performance can be affected positively by optimizing RectTransform.rect.
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Is it feedback or can it be considered a bug?
     
  3. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,698
    Does not feel like it would hurt to open a bug ticket. Worst case it just gets closed. Best case a dev sees whether there is actually some low hanging fruit to improve.
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    It does kinda make sense - the rect property is calculated, while the other properties are just fields. It also (probably) needs to walk the hierarchy and deal with all the garbage that is layout groups and whatnot.

    Did this get way worse in 2022?

    I sincerely believe uGUI should never have been shipped. It's just a very big bug that pretends like it's a feature.
     
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Not really, a little worse in 2022 only. But it could be fluctuation in profiling too, it was about 0.2ms difference between 2019.4 and 2022.2.

    I just submitted it with 2022 to increase chances that Unity staff is looking at the report ;)
     
    LeonhardP likes this.
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I’ve had a quick look at the code and indeed it’s not trivial - it walks the parent hierarchy looking for changes. There is nothing obvious to optimise just by reading it. If a bug report got past QA someone could profile it to get a better idea of the hotspots. The UI team may be focussing on UIToolkit these days though… sorry I dont have any good news about it.
     
    hippocoder and Peter77 like this.
  7. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    uGUI has been basically abandoned since it was moved into a package to open room for UIToolkit. As per usual for anything Unity, development on the old feature stops long before the new one is ready.
     
    richardkettlewell likes this.
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Wow, very cool of you to have looked into it. Thank you!

    I wish Unity would still improve a few things in old systems, because we're still using most of them and will continue to use them even in a few years. Where "we" refers to the company I work. But I understand that you (plural) don't want to break old systems by working on performance improvements for example.
     
    richardkettlewell likes this.
  9. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    Having the UI project repo available on GitHub would be epic, at least then we could submit PRs for improvements (like removing cases of transform.GetComponent<RectTransform>())
     
    Gekigengar likes this.
  10. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,792
    The problem is that it stops before the old one is ready as well.
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I have to say that the regular Particle System is probably one of the most complete things in Unity. You can't really make it do any more that doesn't make sense being done elsewhere. Also a few other bits and bobs feel pretty done to me...

    But IMHO UI was never done because one of the chief objectives of a built in UI would be really high performance as that's kind of why you will use a UI vs just slapping a few quads/sprites/text on the screen. In that, I would say UI was never finished.

    Doing a brand new UI Toolkit thing seems again something fairly separate from DOTS and I've already decided not to use it, based on past experience and the fact it's far from finished.

    Rolling my own UI for my stuff, as I can guarantee the performance and its probably a hundred thousand times easier to use.
     
    karl_jones and richardkettlewell like this.
  12. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
    Hmm, when does HippoUI Pro hit the githubs or the Asset Store? :)
     
    Gekigengar and hippocoder like this.
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Haha I will never sell on asset stores or anything like that. What I mean is in my past games and my current even, I just normalise where the screen edges are and snap 3D objects there like TextMeshPro objects, or health bars, that sort of thing. It's really no different to a game problem like a 2D game. I got the habit of UI like that from @MelvMay many years back when having fun with Torque2D.

    Time flies but evidently UI's don't.
     
    greg-harding and MelvMay like this.
  14. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618