I'm wondering about the performance differences between two different methods of data filtering. Here's what I'm working with:
As I see it, there are two possible approaches here:
I know there are factors that influence the answer (how large the data set is, how often the segmented control will be used), I'm just wondering if there is an overall best practice between the two.
There are trade-offs between the two approaches, and the best choice depends on how important the differences are to you. No one approach is the best practice for every situation.
Loading everything up front in one array will likely have:
Doing a new fetch every time will likely have:
How significant the factors are depends on your data and your app. If you have lots of data, then the memory use may be significant (fetching every instance of an entity type is an easy way to blow out your memory use). Speed concerns depend on what else your app is doing at the same time and, frankly, on whether either option is slow enough to cause a noticeable delay. If your data set is small, it probably doesn't make much difference which approach you use.
I don't expect there will be any user-noticeable speed difference.
Therefore these are best practices that I think are relevant here:
From this I deduce three points of advice that apply to current problem:
To combine those points in one advice, it's best to use the class NSFetchedResultsController
for displaying Core Data in tables as it's specifically designed for this purpose:
You can play with examples of it by creating a new Core Data-based project in Xcode (4.4 or later). It's closer to the second of your approaches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With