Author Topic: More than 1000 UILabels on screen: how to optimise?  (Read 1703 times)

zedarus

  • Guest
More than 1000 UILabels on screen: how to optimise?
« on: July 07, 2013, 01:21:25 PM »
Hello NGUI gurus!

I've run into a bit of a problem. I need to display a lot of characters on the screen (between 1000-2000). All characters have different sizes and some of them are rotated. If I use separate UILabel for each character then performance on mobile devices is really slow (somewhere around 10-12 fps on iPhone3GS), but if I'll use just one UILabel with the same number of characters (even tried 5000 characters) the fps is stable 30. Draw calls number is the same, textures number is the same and vertices number is the same in each case. The only thing that is different is number of game objects for each character.

So is there any way to improve performance in this case?

Thanks in advance for any advice!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: More than 1000 UILabels on screen: how to optimise?
« Reply #1 on: July 07, 2013, 11:27:22 PM »
Having many objects will always be slower than having one object. Moving a widget makes it re-create its draw buffer, which is a slow process. If you have 2000 widgets, that's 2000 buffer re-creations per update. If you have 1 widget, that's only 1 buffer re-creation. So there is your difference.

In your case I wouldn't use labels at all. I'd use raw OpenGL calls (GL.Begin / GL.End, look into that).

zedarus

  • Guest
Re: More than 1000 UILabels on screen: how to optimise?
« Reply #2 on: July 08, 2013, 02:50:41 AM »
Ah, I see now. Thanks for the info and for suggestion, will look into that!

zedarus

  • Guest
Re: More than 1000 UILabels on screen: how to optimise?
« Reply #3 on: July 11, 2013, 03:40:34 PM »
Just wanted to post a solution here.

Using UIFont's method Print() you can get vertices, UVs and colour for any text string for specific font (including dynamic fonts). Translate/scale/rotate vertices as you need and then use them as data for single Mesh object in Unity. Works perfect: I have almost 3000 letters on screen with different position, size and colour and everything runs smoothly on 30FPS even on iPad 1 and iPhone 3GS even if I'm changing colour of some letters each frame.

Big thanks to ArenMook for guiding me in right direction!