views:

30

answers:

0

I'm having a strange performance issue with core data and compound predicates. I have no problem doing very basic predicates or relatively complex ones, but if I try to create one that is 'somewhere in the middle' (a basic numeric match and an 'or' of a to-many relationship; see the 3rd example below), the app becomes un-responsive and hoses the cpu until I kill it. I'm setting keypaths for prefetching, though I'm not 100% sure if I'm doing it correctly since I see no performance increase/decrease. Below are some sample predicates. The first bit of the predicate (set.id == 64) restricts the query from ~15,000 objects to 350.


09:57:59.017 ~ Performing fetch with predicate: set.id == 64 AND ANY attributes.types.definition.id == 1
09:57:59.762 ~ Fetch complete

Took 745ms - Very slight pause, but acceptable. No idea why there is even a slight pause.


10:00:00.931 ~ Performing fetch with predicate: set.id == 64 AND (attributes.isColorless == 1 AND ANY attributes.types.definition.id == 1)
10:00:00.947 ~ Fetch complete

Took 16ms - Awesome performance


10:23:29.090 - Performing fetch with predicate: set.id == 64 AND (ANY attributes.types.definition.id == 1 AND ANY attributes.types.definition.id == 2)

Fetch never completed. Killed the app after 5 minutes of 100% cpu use and no response.


10:22:40.005 ~ Performing fetch with predicate: set.id == 64 AND ((ANY attributes.types.definition.id == 1 AND ANY attributes.types.definition.id == 2) OR ANY attributes.types.definition.id == 3)
10:22:40.016 ~ Fetch complete

Took 11ms - More complex than the predicate above, but performs great. Anything more complex than this performs equally.




Below is how I have setRelationshipKeyPathsForPrefetching setup. I'm not sure if it has any bearing on the above but again, I'm not sure, so here it is:

[fetchRequest setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"rarity", @"artist", @"userData", @"attributes", @"attributes.types", @"attributes.supertypes", @"attributes.subtypes", nil]];




Any tips on where I may be going wrong would be great. Let me know if you need to see any more code or need any more info.