Author Topic: Huge spikes on UIPanel.LateUpdate  (Read 7745 times)

rextr

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Huge spikes on UIPanel.LateUpdate
« on: August 06, 2013, 02:06:07 PM »
Hi,
First of all, thanks for this great tool. I have been using it for almost 1 year now.
Recently I have switched to Pro version of Unity and run the Profiler. I have noticed some huge (17ms) spikes caused by UIPanel.LateUpdate (GC.Collect).

My GUI has nothing fancy. There are some HUD elements and some UILabel, the text of which is updated every frame. (Current speed of the car, etc.)






I'm using Unity 4.2 Pro and NGUI 2.6.4
So, what can I do to reduce this spikes? Or is it already a know issue?

Thanks

-Soner

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Huge spikes on UIPanel.LateUpdate
« Reply #1 on: August 07, 2013, 05:31:07 AM »
Seeing as you're using the latest version of both Unity and NGUI, your performance should be pretty solid. NGUI version 2.6.3 optimized garbage collection greatly on Unity 4.1+.

Do you have a frequently changing UI? I recommend limiting the frequency of updates. Tweening a color of a widget every update will result in buffers to be re-created, thus increasing GC and reducing performance.

rextr

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Huge spikes on UIPanel.LateUpdate
« Reply #2 on: August 07, 2013, 10:56:48 AM »
There is no color tweening in the UI. There are only 5 UILabels, the text of which are updated every frame. (score, speed, distance, combo, high speed). I can really notice the game stutters when the spike happens.

galuodo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: Huge spikes on UIPanel.LateUpdate
« Reply #3 on: August 07, 2013, 11:27:28 AM »
You can try to not to use the temporary variables, and do not change the content every frame.
And event there is a  spike, the fps keeps near 60, so that will not usually cause a stutter. You can also try to on the deep profile to check out which script causes these spikes.

Callabrator

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Huge spikes on UIPanel.LateUpdate
« Reply #4 on: January 05, 2015, 06:49:07 PM »
Seeing as you're using the latest version of both Unity and NGUI, your performance should be pretty solid. NGUI version 2.6.3 optimized garbage collection greatly on Unity 4.1+.

Do you have a frequently changing UI? I recommend limiting the frequency of updates. Tweening a color of a widget every update will result in buffers to be re-created, thus increasing GC and reducing performance.

Is it fair to assume that a tween of ONLY the alpha (and not the rgb) will cause the same reduction in performance?  I'd tween the alpha by playing a legacy animation on a TweenAlpha script.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Huge spikes on UIPanel.LateUpdate
« Reply #5 on: January 06, 2015, 10:45:47 AM »
Is it fair to assume that a tween of ONLY the alpha (and not the rgb) will cause the same reduction in performance?  I'd tween the alpha by playing a legacy animation on a TweenAlpha script.

Yes it will trigger a full rebuild of the geometry / redraw.

Put everything that updates every update into its own panel (it can be a single panel with all these things) so that you minimize how much static stuff gets needlessly reloaded. Also check if the value is actually different than what you're setting before setting it, then you may (or may not) save the reload that frame.

  1. string myNewScore = "200";
  2.  
  3. if(myLabel.text != myNewScore) myLabel.text = myNewScore;
  4.  

It may already be doing that optimization under the surface, but I'm not certain.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Huge spikes on UIPanel.LateUpdate
« Reply #6 on: January 06, 2015, 11:09:47 AM »
NGUI does inequality checks under the hood.