Shared timer

Hi !

Here’s my problem : I have an app which contains something like 15 VU meters, and for now, every VU meter has his own timer, which is 15 timers only for them. Every TimerCallback, I do a checking to know if I need to repaint() them, one by one, and I think it’s pretty optimized there (the condition of the potential repainting)
I’ve set my VU meters to opaque to avoid 15 repainting of the parent component, and my only “problem” for optimisation is now the timers, because my app uses up to 120% of the CPU of my iPad 4 WiFi, which seems a lot to me, but maybe it’s “normal”

So, is there a way to actually make all the VU meters to use the same timer, and each one of the VU meter uses his own timerCallback()

Thanks a lot !

Did you use a profiler? (I don’t think the number of timer really impact the cpu very much, its more whats happening inside callback which causes the CPU load)

I’ve tried, but I can’t really tell what is what in there, not the best around here haha
Any advice on what to look for ?

First of all I forgot one simple thing : Thanks @chkn !

But I guess the 120% is the minimum that I can get to run this app then, the multiple timers are the only thing that I think can still be optimized, my repainting and some small calculations that are in my callback are pretty optimized already I’d say.
Just to do something clean, any advice on a unique timer then ?

The only advantage I can think of in coalescing multiple timers would be to reduce the number of thread wake-ups that happen to the timer’s internal thread, but that’s a very esoteric edge-case that would only have a noticeable impact in a tiny number of situations.

It’s a really bad idea to make guesses or assumptions about where performance problems come from, you’re almost always going to be wrong - there’s no alternative for profiling and measuring it properly.

Alright, thanks !

I’ll try to track it by profiling it then !


You can bench by comparing your current implementation where every VU has its own timer with a small change of your code, said small change being disabling your VU timers and “hooking” the timer callback to a common timer. Compare performances. Conclude. Advertize. (and Party)