Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Ferazel on March 31, 2014, 03:58:23 PM
-
Hi ArenMook,
We're doing an optimization pass on our game and there were a couple things that I was seeing that might be candidates for optimization.
Currently in UICamera 1239 there is an alloc that is happening every frame due to:
inputHasFocus = (mCurrentSelection != null && mCurrentSelection.GetComponent<UIInput>() != null);
It's appearing as a 0.6KB GC alloc in the profiler. Would it be possible to check/remember the current selection's input by doing that check only when the selection is changed in Changed Selection? It appears that ProcessTouch/Mouse() methods set mCurrentSelection directly, but I'm wondering if they could go through the ChangeSelection coroutine and then only check for UIInput if a new selection was made?
My UI as a whole is consuming about 10% of my CPU frame time:
6% UIPanel.LateUpdate
3.1% UIRect.Update
1% UICamera.Update
These aren't awful by any means, but I notice that you were using the standard Update() on the UIRect. In the profiling tests that I've done, directly calling a MyUpdate() from a manager object is faster than relying on Unity's Update() call (which I would assume is using a slower reflection call). Since all widgets are managed by a UIPanel in the sense of draw calls, would it be possible to have each panel call a MyUpdate() on the widgets instead of relying on a Unity's Update()?
If I'm misinformed, please let me know.
-
Widgets may not be managed yet in Update(). If you look at UIWidget.OnUpdate, you will notice that the first thing it does is creates a panel if it's missing. This is where the widget actually ensures that it has a panel to manage it. And nope, I can't do it in OnEnable. It has to be in Update.
I'll move the GetComponent<UIInput> into UICamera.ChangeSelection. No reason to keep it where it is. Thanks for pointing it out.