How expensive is it to complete a fetch query in Core Data?

How expensive is the executeFetchRequest call for a managed control? Does it depend on the size of the dataset? Is this something that can be done often or should be avoided as much as possible?

+4
source share
2 answers

It is relatively expensive. Each choice you make involves moving from context through the model to persistent storage, which in itself implies access to the file. At best, your selection will be as slow as accessing the repository file. In some cases (especially for obtaining large binary BLOBs) this will be much slower. Choose with caution.

However, remember that sampling is not as expensive as an error. You should be more worried about crashes in crashes in access to data than to make additional selections. In addition, running one or more large sets is much cheaper than running many small sets (just as accessing one large file is easier than accessing a hundred small ones).

The best policy is to try to anticipate what data will be needed when developing the application, then pull it out at once or in several large samples and cache as long as you can.

+5
source

As in most cases, pre-optimization is never good. Retrieving yourself is rarely a bottleneck for the application, and when it is, it will be obvious very quickly.

I don’t care at all about sample performance or even crashes until I notice a performance problem. Then it is time for optimization.

As long as you have an application assembled together and running data through it on real hardware, it’s quite difficult and, as a rule, to spend a little time guessing where the bottlenecks will be. Assembly, testing and supervision.

+6
source

All Articles