Optimising Path drawing

I have a timeline component, which displays an editable curve; effectively like an automation channel in a sequencer.

The curve is represented by a Path, and it all works very nicely. However, if I set my horizontal zoom to something very large, drawing this Path becomes incredibly slow. Only a tiny fraction of the path as a whole is actually visible (zoomed in such that it looks effectively like a straight line, with the majority of it outside the screen bounds), but it struggles plenty.

Is there a way to improve this kind of performance with Paths? Maybe clipping a path to a Rectangle? I get the feeling my only option is to only generate as much of the curve as would be visible, but that would be very fiddly indeed with the system I am using.

Yeah, when you zoom right in it’ll be creating a really huge off-screen curve, and will have to subdivide it into many more line segments than if you were rendering it at a small scale. I can’t really think how you’d optimise that, there’s no way it can know whether lines are on-screen until it has generated them all…

It’d certainly be better to only generate the section that you need if that’s possible - certainly in the case of an automation curve I’d have thought that it’d be much more sensible to store it in some other format and only use a path for rendering it when you need to.

Yeah, I’m certainly not storing my actual significant data in the Path, I’m just using it for the UI.

The way my curve is held is as a series of non-linearly-spaced value nodes. Each node specifies a curve shape to use (defining the interpolation method, e.g. hermite ease-in/out, sine ease in, sine ease out, linear, cubic with control handles, etc…). Each shape type has a handler class which (amongst other things) produces a normalised path segment [0,0 to 1,1], which is then transformed to fit between the two corresponding value points in the main path.

My first thought was that I could just ignore segments that are not visible, but that doesn’t help if there are only two steps.

I think my course of action is to change the normalised segment generation to only return as much of the path as is required [i.e. take min/max input]. I’d planned on having the shapes cached as most of them don’t change. However, I guess it’s a lot faster to generate a simple curved line Path segment than to try to render excess path.