Is it faster to clip a line myself before drawing or let clip rect handle that? I have a graph that sometimes draws between a point on my graph and a point well off the graph bounds, which I want to clip at the graph bounds (where my graph and its lines are drawn on a larger component in its paint() function, not in its own Component). I am wondering which is faster in practice: just drawing as is and letting the clip rect clip the line, or having code that computes the intersection of my line with the edge of the graph and clips to it before drawing the line? Does it matter? I could try both and instrument the drawing in both cases, but if someone knows the best practice in terms of drawing speed, I’d like to avoid the work of comparing two different solutions. Thanks!
This will depend on what version of JUCE you’re using. If you’re up to date with the the tip
Of develop, switching off clipping of the component saves a very small amount (in the order of microseconds) and unless you can draw the line you need without applying any clipping at all I think you’re probably unlikely to save much if anything.
If you’re using a slightly older version of JUCE, turning off clipping of a component can save a lot more (to be clear in newer versions of JUCE you are now getting most of these savings by default), but this depends enormously on the layout of your components and where in the component tree this component sits, making it very difficult to give a simple answer.
We are currently working on releasing a new feature that makes measuring exactly this kind of thing much easier.
I realised after responding that you might be referring to if there is any cost in drawing a line well off screen, and as far as I can tell in a quick test I ran up that the answer is no for any of the renderers on macOS. The length of the line on screen did make a difference for the software renderer but not the CoreGraphics renderer.
