Array filter vs. Core Data pull performance
core-data, ios, objective-c, uisegmentedcontrol, uitableview
Solution
I don't expect there will be any user-noticeable speed difference.
Therefore these are best practices that I think are relevant here:
- Avoid premature optimization.
- You're constrained by memory more often than speed.
- Design in advance.
From this I deduce three points of advice that apply to current problem:
- Go with the method that is easiest to maintain.
- Don't pull more objects from Core Data than necessary.
- Have some strategy about updating the data in the tableview.
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:
- Encapsulates the idea of "the chunk of data I'm currently displaying".
- Saves you memory by not pulling things you don't need.
- Helps with updating data in tableview.
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.
Problem
I'm wondering about the performance differences between two different methods of data filtering. Here's what I'm working with: - A set of core data objects - A UISegmentedControl that represents a boolean filter (learned vs. not learned) - A UITableView that displays the filtered data set As I see it, there are two possible approaches here: - Pull the entire core data set in viewDidLoad. Filter the array of data using a predicate when the segmented control value changes. Reload the tableview. - Initially pull the core data set with a predicate. When the segmented control value changes, re-pull the core data set with the updated predicate. Reload the tableview. 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.