Author Topic: UILabel high GC Alloc and Time Ms  (Read 2785 times)

Tester1234

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
UILabel high GC Alloc and Time Ms
« on: October 29, 2017, 07:13:06 AM »
Hi,

I have a UI part which updated every frame ( car telemetry, needs to be updated every frame ). I use stringbuilders to minimize GC Alloc and Time MS, however NGUI UI Label creates extensive amount of GC Alloc and Time Ms

What could be the reason and how can I prevent this ?

Here is Deep Profile screenshot ( attachment )

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel high GC Alloc and Time Ms
« Reply #1 on: November 06, 2017, 07:18:03 AM »
I'm going to venture a guess and say you're doing a deep profile, which is notoriously unreliable for accurate timings. You also don't need to ask what NGUI does. You have the code -- just look at it. My guess is you are assigning the same string value to the label without checking to see if it's already assigned to that. Looking at the code it does an inequality check, but then still adjusts the collider regardless. You can probably address by moving the collider adjustments:
  1.         public string text
  2.         {
  3.                 get
  4.                 {
  5.                         return mText;
  6.                 }
  7.                 set
  8.                 {
  9.                         if (mText == value) return;
  10.  
  11.                         if (string.IsNullOrEmpty(value))
  12.                         {
  13.                                 if (!string.IsNullOrEmpty(mText))
  14.                                 {
  15.                                         mText = "";
  16.                                         MarkAsChanged();
  17.                                         ProcessAndRequest();
  18.                                         if (autoResizeBoxCollider) ResizeCollider();
  19.                                 }
  20.                         }
  21.                         else if (mText != value)
  22.                         {
  23.                                 mText = value;
  24.                                 MarkAsChanged();
  25.                                 ProcessAndRequest();
  26.  
  27.                                 if (autoResizeBoxCollider) ResizeCollider();
  28.                         }
  29.                 }
  30.         }
Although looking some more at your call stack I see it calling ProcessText and WrapText implying the text does, in fact, change. In which case, those few bytes are likely due to text assignment.

I advise you add a few profiler lines to NGUIText.WrapText to track it down if you're still curious -- but considering how few bytes it is, I wouldn't worry about it.