Frustrated iOS search time with CoreData

I have db coredata working on ipad with iOS 5.1.1. My database has about 50,000 companies. I created a company name attribute index. I look for this attribute and sometimes get several thousand records returned with fetchRequest.

When several thousand records are returned, it may take several seconds to return from the selection. This makes foreground search pretty awkward.

I assume that in the future you will have much more databases. What are my options for implementing a really fast search function?

Thanks.

+4
source share
2 answers

I recommend watching videos with master data performance from the last few WWDCs. They often talk about strategies for improving such bottlenecks. Some suggestions from the video:

  • De-normalize the name field to a separate "case and diacritic lensitive" searchString and search in this field using < , <= or BEGINSWITH . Avoid MATCHES and wildcards.
  • Limit the number of results returned by NSFetchRequest using fetchLimit and fetchBatchSize
  • If your company’s object is large, you can extract some of the key data elements to a separate smaller object that is used only for the search interface. Then add a relation to the main object when the user makes a choice.

Some pointers to a couple of videos (there are other years):

WWDC 2012: Session 214 - Best Practices for Basic Data: 45:00

WWDC 2010: Session 137 - Optimizing Master Data Performance on iPhone OS: 34:00

+3
source

While Core Data is the right tool in many cases, it is not a silver bullet by any means.

Check out this post, which discusses several optimization strategies, as well as cases where the SQL database is the best choice instead of Core Data:

http://inessential.com/2010/02/26/on_switching_away_from_core_data

In this case, you honestly can better use the SQL database instead of Core Data, because when you try to access attribute values ​​for Core Data objects, this usually leads to an error and pulls the object into active memory ... it can definitely have performance and speed. Using a true database - Core Data is not a real database, see http://cocoawithlove.com/2010/02/differences-between-core-data-and.html - you can query a database without creating from it objects.

+1
source

Source: https://habr.com/ru/post/1434895/


All Articles