Author Topic: UIPanel.LateUpdate() is killing my game's performance!  (Read 11547 times)

Adratus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
UIPanel.LateUpdate() is killing my game's performance!
« on: December 06, 2013, 11:52:14 AM »
Hi all,

I was wondering if someone could kindly explain what exactly UIPanel.LateUpdate() does, and why it spikes every so often to take up 80% CPU usage during profiling?

Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #1 on: December 06, 2013, 01:14:07 PM »
In which version of NGUI? Late Update is when all the logic of updating widgets and creation of draw calls occur. In the latest version enabling groups of widgets in the middle of the depth hierarchy will cause NGUI to re-evaluate  the entire hierarchy.

didier

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #2 on: December 30, 2013, 08:07:46 AM »
Hello

Am having a similar issue with the 3.0.7 f3 version, but with a 25% cpu load on LateUpdate(), at each frame.
Our GUI (at least the NGUI one) is extremely simple: some label to display. The hierarchy is not the greatest for now because there is an extra panel inside the main panel, but it is disabled so shall not be eating anything.

I guess we are doing something wrong, but i am not sure what it is. Any tips to debug this are welcome.
(the gui is just a tiny part of the scene; so we expect it to use less than 1% cpu)

Profiler:
UIPanel.LateUpdate(15%)
  UIDrawCall.Update
  UIPanel.UpdteTransformMatrix
  UIPanel.UpdateWidgets
 

AND (10%)
UIRect.Update
  UILabel.OnAnchor
  UIRect.Update

Thanks


Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #3 on: December 30, 2013, 11:16:31 AM »
Didier, could you post a screenshot of your UI and the hierarchy, so we can get an idea of what's going on?

My guess is that you're updating the Label but have everything in the same panel, which forces all panels to be updated. Try pushing whatever widgets constantly update to be in their own panel and put them in the top of the depth stack.

didier

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #4 on: December 30, 2013, 11:54:10 AM »
I did some tests and even when i disable all elements in the root panel there is still 5% cpu used by LateUpdate(), which doesnt look right ?
the hierarchy is this one:
(the anchor objects are just empty (no script))
 
« Last Edit: December 30, 2013, 12:30:56 PM by didier »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #5 on: December 30, 2013, 12:58:42 PM »
Try it with 3.0.8 instead. It had quite a few performance optimizations.

didier

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #6 on: December 31, 2013, 09:12:26 AM »
I tried the new 3.0.8. From what i saw there is no difference.

I am adding the profiler screen. The same hiearchy is used and i have enabled the few uilabels we need.

What exactly means those profiler calls?
(for ex Why does the UIPanel need to updateSelf each LateUpdate()?
           Why UIRect OnAnchor is called each Update()?)

(we dont update any label except one but we do it every 1 sec, not every frame)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #7 on: December 31, 2013, 09:35:26 AM »
Looking at your profiler, you're only spending 0.2 ms inside NGUI. Are you really worried about that?

didier

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #8 on: December 31, 2013, 12:17:37 PM »
Hi Aren,

This profiler runs on a desktop. We indeed reach 2K fps on this mahine. On a low end mobile device FPS drops to 15-20.
We are trying to improve what we can, and the profiler shows that 20% are spent in NGUI.



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #9 on: December 31, 2013, 12:35:00 PM »
Then I suggest you actually profile it on the low-end machine. What you see on a high-end machine and what you see on a low-end machine can be very different.

didier

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #10 on: December 31, 2013, 01:35:56 PM »
this is quiet expensive to do a deep profiling on android.

But ok lets forget about the profiler. Is it possible to just have your opinion on this:

Why does the UIPanel need to updateSelf each LateUpdate()?
Why UIRect OnAnchor is called each Update()?

It may just point out something that we are doing wrong, thanks
(we just need to know in which circonstances it would happen)



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #11 on: December 31, 2013, 03:47:19 PM »
Deep profiling does not give accurate results. It's a really bad idea to do deep profiling anywhere, let alone android. Stick to regular profiling.

If you don't know why I say this, think of it like this... each profiler entry adds a certain amount of time to function executions. In deep profiling, all functions inherit this fixed cost, regardless of whether they take 0 ms to execute, or 1000. This means that if you call some insignificant function 1000 times that normally finishes all 1000 calls in 0 ms, it will suddenly take a large amount of time in deep profiling. Compare this to a single function call that takes 1 ms to execute... add the fixed size there, and you won't notice much of a change. Suddenly you will believe that the function that executes 1000 times is the culprit of your performance degradation, when in fact it is not.

10FingerArmy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #12 on: August 06, 2014, 11:28:18 AM »
Hi,

I am in the polishing phase of my game and I see very similar issues (25-70% in lateupdate). I am investigating why mobile is so slow and I can actually draw very good parallels from profiling on desktop vs. mobile. I did tons of build to compare and yes, one can derive meaningful optimizations from that and I can recommend to do so. Sure, some things will be different in the end but some major things can be found.

One really big one I found so far: keeping text crisp. I had it enabled for 7 big 3D texts on my menu and I was at 70% lateupdate. I disabled keep crisp and suddenly was back to 15%. What is the deal with crisp and is this drop expected or is there maybe an error in the logic or in my setup?

Cheers, Robert

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel.LateUpdate() is killing my game's performance!
« Reply #13 on: August 07, 2014, 01:47:06 AM »
Everything related to dynamic fonts is slow performance, and keeping crisp especially. To keep something crisp it often requires shrinking it repeatedly, retrieving new font sizes every time. This is very slow to begin with as each character in a label needs to be queried from Unity. Do this a couple of times per label to get the font's size down to where it fits, and you've got an obvious performance problem. Shrink to Fit option should be used sparingly in any case.