Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: dilshod on October 15, 2014, 05:29:41 AM

Title: Optimization: Can we set OnEnable to UIRect.updateAnchors as default value?
Post by: dilshod on October 15, 2014, 05:29:41 AM
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.
Title: Re: Optimization: Can we set OnEnable to UIRect.updateAnchors as default value?
Post by: ArenMook on October 16, 2014, 06:16:13 AM
Are you doing this with deep profile enabled? They are simple null checks.
Title: Re: Optimization: Can we set OnEnable to UIRect.updateAnchors as default value?
Post by: dilshod on October 20, 2014, 01:31:38 AM
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;
(https://dl.dropboxusercontent.com/u/25941860/a0.jpg)

and profiler when it is
  1. [System.NonSerialized] public AnchorUpdate updateAnchors = AnchorUpdate.OnStart;
(https://dl.dropboxusercontent.com/u/25941860/a1.jpg)
Title: Re: Optimization: Can we set OnEnable to UIRect.updateAnchors as default value?
Post by: Nicki on October 20, 2014, 06:05:33 PM
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.
Title: Re: Optimization: Can we set OnEnable to UIRect.updateAnchors as default value?
Post by: ArenMook on October 20, 2014, 11:49:50 PM
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?
Title: Re: Optimization: Can we set OnEnable to UIRect.updateAnchors as default value?
Post by: dilshod on October 21, 2014, 08:58:24 PM
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.
Title: Re: Optimization: Can we set OnEnable to UIRect.updateAnchors as default value?
Post by: Ferazel on October 22, 2014, 12:39:24 AM
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.