views:

61

answers:

1

My app architecture / hierarchy looks like this:

UIView
UIView
CALayer | CALayer | CALayer | CALayer .... (and a few hundred more)

These CALayer instances represent small square dots in a dot matrix display for an fast countdown clock. I'm updating their backgroundColor as often per second as possible. Actually what I want is 60 times per second, but I guess the device can't do that.

I have an timer which calls an method frequently. This method then iterates over those pixel-dot layers and sets their backgroundColor to whatever is needed right now.

What optimization tips do you have to improve performance?

One thing that comes to my mind:

1) Tell every CALayer that it's opaque!

I guess there are a lot more optimization possibilities. Maybe not a flat hierarchy like I have, but a very deep one, where every CALayer is a sublayer of another? Not sure.

+1  A: 

Couldn’t you simply forget about the layers and render the image each frame using Quartz?

zoul
I think that's very slow. I had tried something like this before, and it turned out to be very bad. -drawRect is slow like an 100 years old snail.
BugAlert
@BugAlert: You're acting on speculation. Go back to @zoul's suggestion and, if there's a problem, find out what it is. If it's that slow, a single interrupt and stack trace will show you the problem.
Mike Dunlavey
I would say that drawing a bunch of filled rectangles can’t be that slow. But as Mike said, in performance matters you have to profile first and think second. In the worst case you can drop down to OpenGL (if that’s possible given the rest of your application).
zoul