Author Topic: UILabel alpha performance hit  (Read 5194 times)

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
UILabel alpha performance hit
« on: May 21, 2012, 11:16:03 AM »
Hi!


I have a "Help" menu in my application which has large amounts of text on it stored in a UILabel.
When this menu is closed, all of its components' alpha value is lerped to 0, making it fade out, then it gets destroyed.
My issue is: Lerping the alpha of a UILabel having a large text results in a huge performance hit on an iPhone 3GS and iPhone 4.
The profiler shows that the UIPanel's lateupdate method reserves the 80% of the available resources when doing the alpha fade.


Is there a workaround to this performance issue?


Regards


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel alpha performance hit
« Reply #1 on: May 21, 2012, 11:40:07 AM »
Yes. By not using alpha blending.

Alpha blending is really slow on mobile devices. You shouldn't use it.

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Re: UILabel alpha performance hit
« Reply #2 on: May 21, 2012, 11:44:55 AM »
Hmm...
Then there is no way to fade the text out? :S

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel alpha performance hit
« Reply #3 on: May 21, 2012, 11:46:14 AM »
There is, but then it's slow.

It's a device limitation. Nothing you can do.

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Re: UILabel alpha performance hit
« Reply #4 on: May 21, 2012, 11:52:25 AM »
I guess i have to come up with something else then.


Thanks for the fast replies, though :)

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
Re: UILabel alpha performance hit
« Reply #5 on: May 21, 2012, 12:01:31 PM »
I just want to say that having a font that isn't alpha blended is not really a solution. Fonts that don't use transparency look awful.

If ArenMook is right and that it is a fill rate problem, decreasing the area of the screen where the font is visible can help.

However, if that if you are truly CPU limited and the profiler is correct, my recommendation would be to try to split up the text into multiple text components. Then only perform the LERP on the UILabels that are visible and disable the other ones. My feeling without much investigation is that performing a lerp on all of those vertices is causing a performance overhead as they are all getting marked dirty as the lerp progresses.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel alpha performance hit
« Reply #6 on: May 21, 2012, 12:36:51 PM »
It's generally not a good idea to have something fade out on mobile devices anyway. Use transform-based animations instead, such as making the window move off-screen or shrink to nothing. They look fancier, and they don't hurt performance (if you do that at the panel level).