I am working on an iOS App that visualizes data as a line-graph. The graph is drawn as a CGPath
in a fullscreen custom UIView
and contains at most 320
This post here gives a nice explanation why that didn't help.
It also explains why your drawRect:
method is slow.
You're creating a CGPath object every time you draw. You don't need to do that; you only need to create a new CGPath object every time you modify the set of points. Move the creation of the CGPath to a new method that you call only when the set of points changes, and keep the CGPath object around between calls to that method. Have drawRect:
simply retrieve it.
You already found that rendering is the most expensive thing you're doing, which is good: You can't make rendering faster, can you? Indeed, drawRect:
should ideally do nothing but rendering, so your goal should be to drive the time spent rendering as close as possible to 100%—which means moving everything else, as much as possible, out of drawing code.