Author Topic: Any way to optimize CalculateRelativeWidgetBounds ?  (Read 1956 times)

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Any way to optimize CalculateRelativeWidgetBounds ?
« on: July 29, 2016, 08:42:30 AM »
Hi,
We have a list of cards in our game.
These cards are displayed in an UIGrid with SmoothTween enabled.
We are trying to do a nice animation with these cards. Every time we add one to the grid(+0.4s), we reposition the grid:


The problem is that we have a scrollbar, and it triggers the CalculateRelativeWidgetBounds function. Since it's a recursive function on all the widgets underneath the panel, it is called 11 000 times !!!! (We have about 50 cards, with one background, an icon, the foreground, and 1 or 2 UILabel)

In our example, we tried to do it progressively, but it started with 0kb of garbage generated and ended with 6Mb of garbage during the last card animation. 6Mb !!!!!!!
We tried to do it instantly on all the cards by giving up the progressive effect (and loose a nice card distribution effect) but the frame still generates 6Mb of garbage.

Do you have an idea on how we can optimize this or change something in our setup to optimize it?

Thank you for your help.


EDIT: I would like to add that this is the GetComponent<UIPanel> on each widget that is generating so much garbage. Would it be possible to cache it and reuse it every time ?
« Last Edit: July 29, 2016, 09:57:13 AM by r.pedra »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Any way to optimize CalculateRelativeWidgetBounds ?
« Reply #1 on: July 29, 2016, 11:12:01 AM »
GetComponent only generates GC allocs in the editor. It doesn't happen at run-time.

Simple solution... why not disable the scroll bar until the animation finishes?

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: Any way to optimize CalculateRelativeWidgetBounds ?
« Reply #2 on: August 01, 2016, 03:58:39 AM »
When you say "run-time", do you mean on device? Because I'm almost 100% sure, it still generates garbage. I will check.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Any way to optimize CalculateRelativeWidgetBounds ?
« Reply #3 on: August 01, 2016, 06:28:15 AM »
Right. I actually added profiler tags to NGUI 3.10.0 that mark editor-only allocations so that people won't think of them as anything harmful.

Note my suggestion about disabling the scroll bar until the end of the animation.