2

I've got a model that's migrating sucessfully but is taking 15-20 seconds. (Obviously this is going to have to be done as a background task not at startup or my app will timeout.)

A 20 second delay, regardless of where it's being done, is bad user experience. I've been looking at the SQL output of the core data migration to see where the major bottlenecks are and I've found this interesting statement

UPDATE ZSIZE SET Z_ENT = ( CASE WHEN Z_ENT = 9 THEN 10 ELSE Z_ENT END ) WHERE Z_ENT IN (9)

This statement seems to be taking 5 seconds (and there are others for the other tables in my db).

Surely because of the IN (9) at the end of the statement it doesn't need to run a case statement per row in the table?

Why doesn't CoreData just run this statement instead?

UPDATE ZSIZE SET Z_ENT=10 WHERE Z_ENT = 9

For bonus points, any other tips / hints about optimizing coredata migrations would be much appreciated!

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • I would shy away from attempting to optimize the migration done by the framework, it's not necessarily the quickest but it is correct. You could instead write your own migration code that would simply copy the data from one store to another and make your performance optimizations there. – ImHuntingWabbits Jun 17 '11 at 07:31
  • I definitely don't want to be doing it myself! I was just interested in why it seems to be doing nonsensical things :) – deanWombourne Jun 17 '11 at 09:03
  • Haha sure, it looks like the root cause is that you changed the entity type (either by switching the parent entity or the entity name) for one of your entities. The case statement is actually the most correct way to update that value in the table, especially in the case where multiple sub entities are affected and have to be reparented. I'm not sure however what SQLite will do with that statement, and there isn't quite enough here to tell if that's the real issue with your migration or not. – ImHuntingWabbits Jun 17 '11 at 15:03

1 Answers1

0

Maybe my answer to the question "Example or explanation of Core Data Migration with multiple passes?" is useful. It's about doing migration in multiple passes to be able to show kind of progress to the user.

Community
  • 1
  • 1
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108