Skip to content

Loading…

Improving scroll performance #84

Closed
mharrisn opened this Issue · 5 comments

3 participants

@mharrisn

Hello forgive me if this isn't the correct place for this, but I was hoping someone could provide some suggestions on things that I can do to improve the scrolling performance. I have a grid of photos that could be as many as 400-500 and the scrolling gets a bit choppy after around 100 photos on an iPad 3. The images are 256x256 and I'm displaying them at 128x128, so there are 7 columns across the screen in landscape orientation.

I'm new to iOS so I don't doubt that I'm doing something wrong. I have view with controls that act as a filter for the photos and each time a control is activated, I call reloadData. Are there general best practices that I can explore to improve performance for this?

Thank you

@rasmusth

First of all you shouldn't call reloadData, if your intention is to reload, remove or add a single cell. GMGridView has methods for at and their easy to find in the main header file. Below is an example of how my implementation is. I'm utilizing NSFetchedResultsController so my code may differ from what you want, but you should be able to get the idea.

- (void)controller:(NSFetchedResultsController *)controller
   didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath
     forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath
{
    if (!self.suspendAutomaticTrackingOfChangesInManagedObjectContext)
    {
        switch(type)
        {
            case NSFetchedResultsChangeInsert:
                [self.gridView insertObjectAtIndex:newIndexPath.row animated:YES];
                [self updatePageControl];
                break;

            case NSFetchedResultsChangeDelete:
                [self.gridView removeObjectAtIndex:indexPath.row animated:YES];
                [self updatePageControl];
                break;

            case NSFetchedResultsChangeUpdate:
                break;

            case NSFetchedResultsChangeMove:
                [self.gridView removeObjectAtIndex:indexPath.row animated:YES];
                [self.gridView insertObjectAtIndex:newIndexPath.row animated:YES];
                break;
        }
    }
}
@mharrisn

I want to make sure I understand what you recommend...My filtering controls don't just remove a single cell from the NSArray at a time. For example, a section of the controls represent keywords, each of which have a relationship with the Photos...so when a user taps a keyword, I run a fetch on the Photos with that keyword as a predicate. Thats when I run reloadData....at that point out of 400 photos, the remaining array that fits that predicate could contain 50.

Are you saying that using the delegate methods for NSFetchedResultsController is the way to go?

@rasmusth

Yes, NSFetchedResultsController will make sure that you only reload the photos that you actually need to, however with that many I don't know how much it'll help. You have to realize that the iPad does have a limited amount of renderingpower. You aren't scaling the images or transforming them somehow right? Cause if you are you should make sure not to do that.

@mharrisn

No the images aren't scaled or anything. I'm just adding the image to the cell's contentView. I ran Instruments and it looks like the longest running function is something called readXMPData, so maybe I can try re-compressing my images and somehow remove the XMP metadata. Thanks for your information I'll keep plugging away at this.

@mharrisn mharrisn closed this
@acecapades

rasmusth can you also help me. I have a similar problem with GMGridView: http://stackoverflow.com/questions/12776371/gmgridview-with-nsfetchedresultscontroller-data-not-updating-reloading.

I implemented your solution but it doesn't seem to work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.