Dangerously fast repaint?


I’m using a stripped-down repaint function for meters etc., haven’t had any trouble with it yet, and was wondering if A: It’s certain doom waiting to happen or B: a fast repaint should be part of the library.

[code]void fastRepaint ()
if (mParent != getParent())
mParent = getParent();
mPeer = mParent->getPeer(); // getPeer() takes a week or so
if (mParent->isVisible())
mPeer->repaint (mX, mY, mW, mH);

[/code]I haven’t had problems (so far), but I’ve only been using this for a week or so.

It doesn’t check if the message manager is locked (I only ever call this from the message thread), the normal repaint() is still there for when the component gets dirty.

Is comparing the last parent a safe way to bypass calling getPeer every time? Or is it one of those perfect 99.9994% of the time deals?


Dave Heinemann


Yeah, I wouldn’t put something like that into my code. You’ll probably get away with it, but not forever.

But surely getPeer() takes a negligible amount of time? There’s very little in there, esp if you only have a couple of top-level windows.


Hmm, getPeer is not nearly as slow as it looked in the disassembly. 725 instructions for something that (theoretically) should be constant until deleted, but it came out to about 5 millionths of a second.

It does call two locks, so I was worried about it stealing time from other threads.

Mainly the host redraw is what suffers, but when I put the meter refresh rate at 15/sec everything is pretty smooth, though 25/sec starts locking the host out. This is with 4 meters per instance (low mid high & output), and my test project has 4 instances, more than you actually need open but a decent test of the limits.

Overall, optimizing paint() was the most beneficial. A pre-drawn image with gradients and shading beats a plain-vanilla fillRectangle, not just for looks!

I’ve just been doing fine-tooth optimization, looking for any last cycles I can save without making the effect sound worse. The meters are definitely the most time-consuming besides the effects themselves, but at this point they’re consistently good enough.

Dave Heinemann