Author Topic: Optimization: Can we set OnEnable to UIRect.updateAnchors as default value?  (Read 3701 times)

dilshod

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 7
  • Posts: 14
    • View Profile
Hi,

Right now UIRect compares 4 transforms (leftAnchor.target, rightAnchor.target, ...) on each Update, even when it has no anchors.
In my case, UIRect.Update is using 28% of cpu time for 500 widgets without anchors, and it is using 12% of cpu time when i change default value to OnEnable.
« Last Edit: October 15, 2014, 09:19:59 PM by dilshod »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Are you doing this with deep profile enabled? They are simple null checks.

dilshod

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 7
  • Posts: 14
    • View Profile
Are you doing this with deep profile enabled? They are simple null checks.

Yes, i'm doing deep profile.
Here is profiler when it is
  1. [System.NonSerialized] public AnchorUpdate updateAnchors = AnchorUpdate.OnUpdate;


and profiler when it is
  1. [System.NonSerialized] public AnchorUpdate updateAnchors = AnchorUpdate.OnStart;

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Be aware that Unity's deep profiler adds overhead per each method call, which will skew your numbers. What is the difference with a regular profiler? And if you could get the profiler on a build instead of the editor as well, that will give much more representative results.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Yeah, always take the deep profiler's numbers with a huge grain of salt. I've explained it numerous times before. Think about it. Deep profiler adds a fixed amount of overhead to every function. So for example, say it adds 0.1 ms to every function call. Now say you have a function that takes 5 ms to execute, and is called once. You also have a function that takes 0.001 ms to execute, but is called 500 times. Let's do the math now:

(5 ms + 0.1 ms) * 1 = 5.1 ms for the big function
(0.001 ms + 0.1 ms) * 500 = 50.5 ms for the small functions.

See the problem?

dilshod

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 7
  • Posts: 14
    • View Profile
Yeah, always take the deep profiler's numbers with a huge grain of salt. I've explained it numerous times before. Think about it. Deep profiler adds a fixed amount of overhead to every function. So for example, say it adds 0.1 ms to every function call. Now say you have a function that takes 5 ms to execute, and is called once. You also have a function that takes 0.001 ms to execute, but is called 500 times. Let's do the math now:

(5 ms + 0.1 ms) * 1 = 5.1 ms for the big function
(0.001 ms + 0.1 ms) * 500 = 50.5 ms for the small functions.

See the problem?

Thank you for explanation!
I have to try it on device.

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
I do agree that OnEnable should be the default behavior of the anchoring system. If I have a couple dozen widgets all calling Update() it adds up, especially on mobile. From my tests, an Update() that does nothing is not as quick as a direct method call from a controller/manager. We avoid Update calls in all but the necessary controller scripts for this reason. I understand that OnUpdate is probably safer in regards to users getting the expected behavior, but I feel that having a runtime performance impact of Update() is more significant.