Author Topic: Serveral ways to reduce NGUI caused GC Alloc  (Read 1574 times)

sophiepeithos

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Serveral ways to reduce NGUI caused GC Alloc
« on: July 01, 2017, 09:58:18 AM »
I test it in Example 0 - Control Widgets scene on windows standalone player, in unity profiler the GC Alloc of UIPanel.LateUpdate can be reduced from 2.4MB to 1.1MB.
Below is how i do it:
1.if you know exactly how many element will be added to a list, it is better to extend list's capacity first, then do the add. there are serveral places can be improved: UIBasicSprite.SimpleFill, UIBasicSprite.SlicedFill, UIBasicSprite.TiledFill, UIGeometry.ApplyTransform, UIPanel.FillAllDrawCalls, UIPanel.FillDrawCall.
2.NGUI caches at most 10 index buffer, but it can rarely be reused.  lucky you can use a single VaryingList to feed mesh indices to unity, the key point is VaryingList can change its array's length to smaller length without create a new array and copy elements