Core Data Inferred Migration – Automatic “lightweight” vs Manual

百般思念 提交于 2019-11-30 00:48:54

Currently Core Data uses a private class, NSSQLiteInPlaceMigrationManager, to perform lightweight migration. This is a subclass of NSMigrationManager, but handles everything itself in migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:. From the looks of it, this class is actually performing alterations directly on the SQLite store instead of pulling everything into memory as required by manual migration.

This explains why you're seeing the lightweight migration complete much faster.

Unfortunately, even if you use this knowledge of the private APIs that are being used behind the scenes, it doesn't gain you much for getting a progress indication. The value of progress is currently never changed for NSSQLiteInPlaceMigrationManager, it's always zero. The value of currentEntityMapping also seems to remain nil.

Until Apple provides an API, it seems we're out of luck. Do you have a radar number so I can open a duplicate?

What happens when you define the mapping model yourself instead of using an inferred model? Sounds like the creation of the inferred model is causing a performance hit that defining the mapping model directly and including it in your project would solve.

update

I already tried that strategy and using a mapping model generated in XCode results in approximately the same processing time as the inferred-at-runtime model. The only real difference is the time to load the model from the bundle is slightly quicker than inferring at runtime. Furthermore once a mapping model is bundled in the app, the automatic migration ceases to be lightweight, I assume it is using the bundled model. Removing the mapping model from the target brings the processing time back to ~4 seconds for automatic-lightweight

That is certainly counter-intuitive. Is your project simple enough to post as an example of this inefficiency or do you perhaps have a test project that isolates this issue? In either situation it would be very helpful to take a look at it so that we can A) hopefully solve the mystery; or B) file it as a rather large bug with Apple as the reverse should certainly be the case.

How large is the data set you are working with?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!