开发者

Bad performance Core Data CONTAINS predicate

开发者 https://www.devze.com 2023-04-10 14:45 出处:网络
I\'m using the NSFetchedResultsController to show some search results in a UITableView. The search results are requested by the following predicate:

I'm using the NSFetchedResultsController to show some search results in a UITableView. The search results are requested by the following predicate:

[NSPredicate predicateWithFormat:@"(plainText CONTAINS %@)", _searchString]

The entity where the search is going through has about 25.000 objects. The plainText property contains a String value with approximately 700 words each.

This search takes about 20 seconds wich is way too slow.

Is there any way to optimize the performance?

I watched the WWDC 2010 Session 137 where she is talking about normalizing the keywords into a separate entity to avoid using CONT开发者_运维问答AINS. This is a way to improve it, only I have 700 keywords each. Making it 700 x 25.000 = 17.500.000 keywords. I doubt it will improve. Should I even try?


Searching 700-word attribute in 25,000 entities for a string will indeed be slow, yes. Your wwdc idea is correct - you'd want to make a separate entity which is a single 'keyword', with a to-many relationship back to your entities. That way, you will very quickly find the one keyword entity, and then very quickly find the entities out of your 25,000. This way you'll avoid searching through every very long string.

tldr; yes, you should try

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号