Вопрос

In my iOS application I use a UIScrollView and a UIPageControl to display three CPTXYGraph plots for different time periods, i.e. one shows the last 30 days of data, the next the last 90, the third the last six months worth of data.

i.e Last Month enter image description here

Last 90 enter image description here

etc

The combination of the UIScrollView and UIPageControll allowed me load each graph and then let the user swipe from graph to graph to view the different time periods.

Everything was working great until I tried to make my app a universal app, and attempted to run it on the iPad. When I rotated the iPad the app would crash and cause the iPad to do a soft reset. While hooked up to the debugger the iPad would report low memory warnings before crashing.

I found setting CollapseLayers = true on the CPTGraphHostingView I could then run the app on the iPad without crashing, however loading the extra graphs on the other pages was orders of magnitude slower than what I could do on the iPhone. Granted I'm using a iPhone 5s vs an iPad3, but I didn't expect such a signification slowdown like I was seeing.

Puzzled, I loaded the app back on the iPhone with CollapseLayers = true still set and noticed the iPhone had slowed down noticeably loading the horizontal graphs as well. See the Instruments captures below

First with CollapseLayers = false enter image description here

Second with CollapseLayers = true enter image description here

In each capture I'm doing the same amount of 'work' on the iPhone, start the application, and rotate. Notice when CollapseLayers = true the amount of time spent by the CPU at 100% is significantly longer than when CollapseLayers = false, but the memory usage is much less, approximatly 38MB vs 199MB.

Suggestions on how I can either reduce memory usage so I don't need to set CollapseLayers = true, or how I can improve performance with CollapseLayers = true?

Update

I found a discussions addressing this topic:

https://groups.google.com/forum/m/#!topic/coreplot-discuss/LqMJEPyuR1o

From the post

The rendering speed is CPU-bound, so unfortunately the higher resolution demands 4 times more work, which is about what you see.

This at least explains why I'm seeing such a performance hit on the iPad3 vs the iPhone.

Tried removing the theme from my graphs and leave CollapseLayers = false, sadly this still crashes the iPad.

Это было полезно?

Решение 2

For anyone who finds this question in the future, my solution for now is to change graphing frameworks. I'm not sure if I'm running into an issue using core-plot in Xamarin.iOS and that is contributing to the issue or not, but trying all of the other answers to this question and other researching I could not improve performance/reduce memory usage on the iPad.

For now I've moved on to using OxyPlot https://oxyplot.codeplex.com.

Performance and memory usage are a fraction of what I was seeing with core-plot, giving me a path forward.

Другие советы

Setting collapsesLayers = YES tells Core Plot to draw the entire graph into a single Core Animation layer rather than use separate layers for all of the various elements (axes, plots, labels, etc.). This reduces memory usage but forces the entire graph to redraw if anything changes instead of just redrawing the parts that changed. Make sure the graph isn't redrawing multiple times after you create it. Remember that any change to the graph or the hosting view will force it to redraw once it has been displayed.

if you are using a table view to display same CPTGraphHostingView in multiple charts the each layer it makes in its delegates methods of plot remains in the memory .. which keeps on increasing , which i guess is the issue in CorePlot Library

So i have found a better option for this : In your table view's cellForRowAtIndexPath method create something like - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GraphCell" forIndexPath:indexPath];
if(cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"GraphCell"];
}
for (id v in cell.contentView.subviews)
{
    if ([v isKindOfClass:[CPTGraphHostingView class]])
    {
        [v removeFromSuperview];
    }
}

self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:cell.contentView.bounds];
self.hostView.allowPinchScaling = NO;
[cell.contentView addSubview:self.hostView];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top