Efficiency of calling repaints on components that are visually unchanged

Hi There,

Let’s say I have many components, and on some user event I click a component which visually changes that single component only.
If I naively call repaint on all the other components including the one that was clicked, only the one that was clicked will visually change because each repaint checks for whether it was clicked.
What I’m wondering is if calling repaint on these unchanged components even if they visually look unchanged is causing some huge performance overhead behind the scenes if there are around 500-1000 of these.
In other words, upon clicking for the mouse event, is it more efficient for me to check whether repaint is worth calling (or whether a sendpropertychangemessage if using a valuetree is worth calling) before actually sending that message or calling repaint - to prevent unnecessary repaint calls basically.

Or, does repaint() automatically see that nothing needs to be changed and therefore this call (to change nothing) is fairly lightweight in this context.

Many thanks in advance.

Sadly, that’d be impossible, as it can’t possibly know what code your repaint() method will run!

So, yes, it’s best to avoid repainting where possible, but the golden rules of optimisation apply, like they do to everything:

  1. Keep your code simple and don’t optimise unless you need to.
  2. When you think you need to optimise, always profile first.

ah an answer from Jules himself. This was actually a question I had because of your talk I just watched. Thanks heaps and great talk too.