tobihagemann / THLabel

UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.
https://tobiha.de
Other
665 stars 111 forks source link

DrawRect is Extremely CPU intensive #31

Open EmperiorEric opened 9 years ago

EmperiorEric commented 9 years ago

I used this label in a game that was running 60fps. My entire game update loop ran about 40% of the CPU at the my intense parts. THLabel ran at 14%. Those percentages are over a minute of gameplay with the THLabel changing its text once a second.

I had to work around it with snapshots of THLabels for various words generated before the game starts.

However, looking at the DrawRect briefly I see some places for speed improvements. It will likely never be fast enough for 60fps rendering as I know Core Text can be extremely expensive. But every little bit of CPU we can save means better battery life under normal operating conditions.

As people fill this thread with ideas, I'll see if I can find time to implement a few.

tobihagemann commented 9 years ago

Thanks for your feedback! So far I just have guessed that performance could be an issue, but I have never done any benchmarks.

Let's say we call drawRect: 60 times a second, and 59 times it's just drawing the same text over and over again. We could save some computation there! Caching (and thus filling up some memory) should improve performance.

That's the only thing that I can think of at the moment...