Shared timer


#1

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 !


#2

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)


#3

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 ?


#4

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 ?


#5

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.


#6

Alright, thanks !

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

Thanks


#7

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)