New Core Data Performance Notes

I was looking through the recently-updated Core Data Programming Guide and noticed a few things that seemed worth mentioning. First, it looks like you can use a simple strategy to improve the responsiveness of the app during fetch:


If you do need to retrieve a large number of objects, you can make your application appear more responsive by executing two fetches. In the first fetch, you retrieve a comparatively small number of objects—for example, 100—and populate the user interface with these objects. You then execute a second fetch to retrieve the complete result set (that is, you execute a fetch without a fetch limit).


Also, the document outlines some basic strategies for building streamlined predicates, which are (not suprisingly) similar to the ideas used in SQL databases. For example, if you have a multiple-criteria search—also known as a compound predicate—it's better to put the most restrictive clause first.

In addition, it's best to do numeric comparisons first because Unicode text searching is much slower by comparison. The idea is to limit the number of bits the processor has to manipulate for a given fetch.

For example, if you want to run a search for all Task objects that are both flagged as complete and have the search string "implement" in them, it's best to structure the predicate like this:


(complete == 1) AND (name like '*implement*')


The rational here is that you'rre likely to chop off a good percentage of the tasks with the first clause, and only have to search the text of the Tasks that remain after that point.

The docs also note the fact that it's much better to use the IN operator to test for multiple values than to run multiple fetches:


categoryName IN { 'implement', 'fix', 'design }



I sure wish I could get my hands on the Core Data icon so I didn't have to use the Core Image one for posts anymore :)
Design Element
New Core Data Performance Notes
Posted Aug 20, 2005 — 0 comments below




 

Comments Temporarily Disabled

I had to temporarily disable comments due to spam. I'll re-enable them soon.





Copyright © Scott Stevenson 2004-2015