Database Reference
In-Depth Information
check for disk hits. If we are getting far more calls to the disk than expected,
we need to consider refactoring the code.
4.5
Access Patterns
Improving performance within Core Data is not necessarily only about the
repository and order of loading the data. There are a number of things we
can do within the user interface to help performance as well.
Searching
Searching the repository can be absolute murder on performance. Whether
we are searching at the request of the user or performing a search in the
background, we need to be very careful to avoid impacting the performance
of our application.
Order Is Important
Just like any conditional, the order of the logic is important. Simple equality
is faster than inclusions such as in , contains , and so on. When building the
predicate, try to order the logic from left to right, simple to complex. This
process allows Core Data to fail quickly and improve the search performance.
Unicode and Regular Expressions
Unicode is very expensive to work with when we are searching. As suggested
earlier in Search-Only Properties , on page 66 , try to avoid searching against
Unicode directly. It is cheaper to keep a derived value that strips off the Uni-
code than it is to do frequent searches against the Unicode text.
Likewise, regular expressions are expensive. If a situation calls for one, try
to put it at the far-right end of the NSPredicate , as discussed in Order Is Impor-
tant , on page 75 .
Limit Queries Across Relationships
Searching across objects that are joined by a relationship can be very
expensive for searching. Although it is impressive to search against
person.address.postalCode.city , it may not be the most efficient way to solve the
problem. Consider reversing the query or breaking it down into several
smaller queries to reduce the complexity of the underlying SQL. When we are
working with a SQLite back end, all of our NSPredicate calls turn into SQL before
hitting the database. The less complex that SQL is, the faster it will run. It
may very well be faster to get an NSArray of all the Address objects within a spe-
cific city and then perform the rest of the query against that NSArray than it
would be to traverse three relationships in one call.
 
 
Search WWH ::




Custom Search