Author Topic: Issues with ScrollView and Panels  (Read 8011 times)

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Issues with ScrollView and Panels
« on: February 17, 2014, 05:52:31 AM »
Hi,

Hopefully you can help!

I have two issues when it comes to using NGUI on mobile (our game is mobile-only)

1) I have a scroll view with a grid of items. I have around 24 items each with around 50 widgets. When running this on device, it runs very slow and so I tried a suggestion which I saw on the forum about putting them into a panel as they rarely change (in fact, some content never change) but when I did this, the scroll view no longer clips or draws alpha.

Is there something I'm missing? I've tried setting the Depth correctly but still doesn't seem to affect this.

2) I notice on the profiler that the anchors are taking a lot of CPU time even though it never changes, is there something I can do to only run the anchors code when it's invalidated?

Regards

James

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #1 on: February 17, 2014, 11:53:06 AM »
Heavy use of anchors will decrease performance. It doesn't matter if they change or not, NGUI doesn't know this and has to re-calculate certain values every update. I suggest minimizing their usage.

Panels won't increase performance in your case, and nested panel clipping is not supported in NGUI. Only one panel can clip its contents.

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #2 on: February 18, 2014, 04:35:43 AM »
Thanks for the response.

We've been looking at disabling the anchors after first update, or possibly editing the code and only update the anchors on InvalidateAnchors().

In regards to having 50 widgets per item and 24 items per scroll view, do you have any idea why we get really poor performance? Profiler shows UIPanel.LateUpdate() taking the most time (if we disable anchors).

Note: It only seems to be during scrolling that it's slow, it's fine when it's static.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #3 on: February 18, 2014, 10:18:49 AM »
Do you have a scroll bar? If you're scrolling something that has a scroll bar associated with it it means the scroll bar needs to be rebuilt every update, which is rather slow. In the Scroll View example I make this less of an issue by putting the scroll bar under its own panel so that it doesn't affect other widgets.

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #4 on: February 18, 2014, 12:08:17 PM »
No, just 50 widgets x 24 items.

On a Nokia Lumia 920, it gets 60fps when still, but when I scroll, it drops down to around 25 - 30fps and on lower-end devices it drops to 5 - 7fps.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #5 on: February 19, 2014, 11:42:25 AM »
In the scroll view example the late update barely takes any time with the scroll bar disabled. Most of the time is spent in the Overhead. But the panel there is marked as "static". If I disable that, then the late update takes 0.16 ms, and overhead takes 0.14 ms. Scroll view late update takes 0.12 ms. Where is the time spent in your app?

P.S. I assume you have the latest NGUI?

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #6 on: February 19, 2014, 12:12:44 PM »
I am currently using 3.4.9 so 1 behind the latest.

I don't have things marked static as some things do change, however, they only ever change once. Can we mark them static until we need them to change or invalidate them manually?

I have no scroll bars. Most of the time was UIPanel.LateUpdate(). On low-end device this would take up-to 200ms and on high-end devices around 50 - 100 ms.

We have 1 background image per item, on that we have 16 numbers, 2 letters and 15 circles and we have 24 of these items. From what I can work out, it's doing a re-draw of the items.

At present I have changed it to use render textures, but I will look at making it again so I can send a screen-shot of everything, plus the profile.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #7 on: February 19, 2014, 03:43:44 PM »
Re-draw is assumed, that happens regardless. Do you mean re-fill? If it does a re-fill, you need to determine why that happens. It will happen if you're changing something (which is bad).

You can mark your panel as static at any time.

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #8 on: February 20, 2014, 04:41:42 AM »
I could try marking the panel as static. Just to confirm, you mean the scroll view's panel right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #9 on: February 20, 2014, 09:28:47 AM »
Yup. I changed the scroll view example in 3.5.0 adding a note about it to the description text.

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #10 on: February 21, 2014, 09:04:06 AM »
I have tried the changes, and ran it on mobile (Nokia Lumia 920) and I have very low FPS still.

I have attached a screenshot of the profiler and the Hierarchy + Inspector (with Scroll View selected).

What I have noticed is, when I run it in the editor, I have "UIRect.Update()" called 1,155 times but on device it's "UILabel.Update()" that is called 1,155 times.

On this sample, I have code that only runs the anchor code on first run so I don't understand what could be causing the low FPS.

Do you have any other ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #11 on: February 21, 2014, 02:11:17 PM »
Well, your 1155 widgets are the likely culprit. Doing some math, 6 ms to update all 1155 of them. Divide 6 ms by 1155 and you get ~0.005 ms per widget. Even if you had 100 of them, it would be only 0.5 ms. But you have more than 10 times that number. I would strongly advise you to reduce the number of widgets you're using.

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #12 on: February 24, 2014, 06:23:20 AM »
After working out, I will need 24 items of 15 numbers + 15 sprites + 3 text items + 1 sprite so around 816 widgets.

I notice on device when I have this amount of widgets that the overhead becomes massive.

Have you any idea how I could shrink the amount of widgets needed? Not that once created, the numbers never change, the sprites start hidden and then show over time (behind the number) and 1 of the text items change over time too.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #13 on: February 24, 2014, 04:32:57 PM »
And do you really need to show all of them on the screen at the same time? On mobile platforms you can easily increase performance by doing paged views rather than one giant scroll view. I'd also suggest trying to enable the "cull" checkbox on the scroll view's UIPanel, but I doubt it'll do much in this case.

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Issues with ScrollView and Panels
« Reply #14 on: February 25, 2014, 04:57:24 AM »
We are doing a bingo game and need to show a total of 24 tickets (only 7 (at most) on screen at once) each with 15 numbers, 15 dab sprites and how many numbers to go until you win.

The idea is the user can scroll through these tickets.

We currently use the Cull setting as well as the Static but something seems to cause the Overhead to sky-rocket when I have this amount on device.