views:

227

answers:

2

I've got about 5000-7000 objects in my core data store that I want to display in a table view. I'm using a fetched results controller and I haven't got any predicates on the fetch. Just a sort on an integer field. The object consists of a few ints and a few strings that hold about 10 to 50 chars in. My problem is that it's taking a good 10 seconds to load the view. Is this normal?

I believe that the FRC handles large datasets and handle's batches and such things to allow large datasets. Are there any common pitfalls or something like that because I'm really stumped. I've stripped my app down to a single table view, yet it still takes around 10 seconds to load. And I'm leaving the table view as the default style and just displaying a string in the cell.

Any advice would be greatly appreciated!

+3  A: 

Did you check the index checkbox for the integer you are sorting on in your Core Data model?

Johan Kool
Thanks for this, I never realised you could index fields!
Michael Waterfall
+2  A: 

On your fetch request, have you used -setFetchBatchSize: to minimize the number of items fetched at once (generally, the number of items onscreen, plus a few for a buffer)? Without that, you won't see as much of a performance benefit from using an NSFetchedResultsController for your table view.

You could also limit the properties being fetched by using -setPropertiesToFetch: on your fetch request. It might be best to limit your fetch to only those properties of your objects that will influence their display in the table view. The remainder can be lazy-loaded later when you need them.

Brad Larson
Yes that was it! I couldn't believe it, I though the NSFetchedResultsController handled all of that! Should have properly read the docs and thought about looking at the NSFetchRequest in more detail! Isn't the -setPropertiesToFetch: just for the dictionary return type? There's not much about it at all in the docs and in the core data guide it just uses it to set what to fetch in a dictionary. I'd be very interested if that works for normal fetches too. If it's true then it's a shame it's not better documented!
Michael Waterfall
-setPropertiesToFetch: is new with Core Data in Snow Leopard and iPhone OS 3.0, so the documentation may not have caught up with it. From the presentation on the topic that was given at WWDC, it was indicated that this works with normal fetch requests and causes only the selected properties to be loaded into memory with your managed objects. If you use an accessor for a non-loaded property, that property will be loaded from the database on disk at that moment.
Brad Larson
Ah great, thanks for your help, I'll give them a try :-) I might have a look at those WWDC videos, looks like they will be interesting!
Michael Waterfall