Repaint lag

I’m experiencing a quite weird behavior with juce repainting.

My test application uses normally about 10%-15% CPU when in full screen, but sometimes, it starts to lag and use all CPU (33%CPU, which is equivalent to 100%, as my system runs on 3 cores, PLUS the refresh rates obviously drops 2 or 3 fps, instead of the 20fps it should have.) This lag proceed for 3 to 5 seconds, then it’s back to normal.

The weird thing is the “sometimes” ! I mean, it happen whenever it feels like it ; no regular basis : sometimes even when I am doing nothing at all ! Switching to full screen seems to trigger the “bug”, though. (which is not too surprising, as resized() might generate quite a lot of caculation…) but

  • why doesn’t it always do it at resized() ? sometimes, size changes, and the app does nothing…
  • why does it take so long ? I mean that I can see from the display that the resized() is over, but the app is still lagging during a couple of seconds, so I wonder how my resized() could be at fault after it’s finished doing its job…

Any idea to fix the problem or to help understand better what caused it, will be welcome !
Thanks in advance for your help !

Valentin

PS : Win Vista 32, using GIT tip, and the cpu’s mentionned above are actually debug, but similar behaviour happen in release, just more rarely.

Can’t think of any obvious ideas… Really, the only way to find out would be to profile it and see where the hotspots are.

If the delay is a couple of second, you can easily break it at that time under the debugger and find out what’s going on. Or, use a profiler, but it’s sometime hard to find out the signal in the profiling noise.

Done it : it is “painting”, that is : it is doing some stuff in the repaint loop (rendering graphics, comparing clips, etc), which is exactly what I’d expect it to do, and exactly the same than what it does seconds later, when it’s not lagging anymore… Quite confusing !

So I guess there is no escape to it : I’ll have to do some profiling. I should mention here I’ve never done it before. Can I ask you guys what tools you’d recommand I use ?..

Could be a memory issue - i.e. could you suddenly be allocating a lot of memory for drawing, and causing the OS to thrash around paging other processes to disk to make room for it?

Under Windows, use VerySleepy, it’s free, and quite good for what it does (beware however of the % of time spent in kernel calls, like “KiSomeFunc”).
If you’re on Linux or Mac, the best tool is KCachegrind with its valgrind’s Callgrind skin.

Good point : my app did have memory leaks. After fixing it, I cannot reproduce the problem anymore. The fix has also reduced the CPU load, so I am off trouble… and a bit ashamed that I wasn’t able to think about it myself…

Thanks for your help guys !

Val