• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data performance advice... creating relationships.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data performance advice... creating relationships.


  • Subject: Re: Core Data performance advice... creating relationships.
  • From: Ben Trumbull <email@hidden>
  • Date: Tue, 15 Jan 2008 19:27:29 -0800

Phil,

On Tiger, Core Data only creates indices for relationships (joins). On Leopard, in the modeling tool, you can also specify that an attribute should have a binary index.

Binary indices can't be used for string matching predicates (contains, like, etc) or case/diacritic insensitivity. Literal string equality and prefix searching can use binary indices. As of Leopard, Core Data does not support custom collations.

For queries that cannot use an index (or an index does not exist), Core Data relies on SQLite. Core Data does not fetch everything into memory (instantiate objects) to perform a table scan. Obviously, SQLite walks the table's entire b-tree for a table scan.

Complex text queries (like case insensitive LIKE) can be very expensive as Core Data handles unicode and locale issues. It can be helpful to denormalize some data to make it eligible for a literal string comparison. Some cleverness with literal string operations such as = and < and >= upon a canonical literal string (i.e. a search column v.s. a display column) can produce performance improvements of several orders of magnitude.

It can also be helpful to organize your predicate in order of maximum discrimination to reduce the number of rows SQLite examines. That is, for compound where clauses, put the simplest or most discriminating subexpressions first, and expensive text expressions last.

Both SQLite and Core Data have made significant performance improvements since Tiger (3 years ago). SQLite now has a (primitive) query optimizer. Core Data fetches are much faster, large fetches are implicitly multi-threaded, and memory usage is significantly reduced.

Also, the array controller has a "lazy fetching" option in entity mode, which is a bit like a cursor. This only fetches the identity (PK) of the rows for the entire fetch request, and the actual data for the rows in use (displayed) by the array controller.

Finally, the tools on Leopard should make debugging performance problems easier. Instruments has a standard Core Data template, and the SQL logging includes annotations for durations.

Please file bug reports with bugreport.apple.com early and often. Performance problems are bugs. Deciding not to use a technology because it crashes or it's too slow amounts to the same thing.
--


-Ben
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Core Data performance advice... creating relationships.
      • From: Phil <email@hidden>
  • Prev by Date: Re: How to get pixel information from CIImage of QT frame
  • Next by Date: Re: core data subentities
  • Previous by thread: re: Core Data performance advice... creating relationships.
  • Next by thread: Re: Core Data performance advice... creating relationships.
  • Index(es):
    • Date
    • Thread