{"id":9270,"date":"2014-07-31T19:42:47","date_gmt":"2014-07-31T23:42:47","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=9270"},"modified":"2014-07-31T19:42:47","modified_gmt":"2014-07-31T23:42:47","slug":"core-data-external-binary-data-storage-and-migration","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/07\/31\/core-data-external-binary-data-storage-and-migration\/","title":{"rendered":"Core Data, External Binary Data Storage, and Migration"},"content":{"rendered":"<p><a href=\"https:\/\/medium.com\/@alexedge\/binary-attributes-and-migration-in-core-data-bc7cfb3029fc\">Alexander Edge<\/a>:<\/p>\n<blockquote cite=\"https:\/\/medium.com\/@alexedge\/binary-attributes-and-migration-in-core-data-bc7cfb3029fc\">\n<p>I have benchmarked the difference between migration using binary data with external storage and using just a unique identifier. The sample project is on <a href=\"https:\/\/github.com\/PeepsMedia\/CoreDataMigration\">GitHub<\/a>.<\/p>\n<p>The test creates 1000 objects, each with a unique identifier and (optionally) a video file of 165KB as binary data. By adding a data model version with a new attribute, lightweight migration is performed on the next application launch.<\/p>\n<p>When using binary data with external storage, migration took <strong>37.5 seconds<\/strong>.<\/p>\n<p>When not using binary data with external storage, migration took just <strong>0.6 seconds<\/strong>.<\/p>\n<p>It&rsquo;s clear to see that storing large files in the file system with a naming scheme is the way to go. I have already begun working on an on-disk cache instead of using binary attributes.<\/p>\n<\/blockquote>\n<p>External BLOB storage is important because storing BLOBs as <a href=\"http:\/\/sqlite.1065341.n5.nabble.com\/Effect-of-blobs-on-performance-tp19559p19560.html\">linked lists<\/a> in the database <a href=\"http:\/\/www.sqlite.org\/intern-v-extern-blob.html\">can be inefficient<\/a>. When Core Data added <code>-setAllowsExternalBinaryDataStorage:<\/code>, this <a href=\"http:\/\/samuelgoodwin.tumblr.com\/post\/35481137771\/external-storage-with-core-data\">sounded<\/a> like a good solution to the problem, but <a href=\"http:\/\/restkit.tumblr.com\/post\/38911840391\/on-the-slowness-of-core-data-external-binary-storage\">various<\/a> <a href=\"http:\/\/www.nickkuh.com\/iphone\/core-data-migration-woes-with-binary-data-and-external-storage-data-loss\/2012\/06\/\">problems<\/a> were reported in early versions. It sounds like there are still issues, which is unfortunate because this sort of feature (commonly needed, tricky to do well) should be a selling point for a more full-featured framework like Core Data.<\/p>","protected":false},"excerpt":{"rendered":"<p>Alexander Edge: I have benchmarked the difference between migration using binary data with external storage and using just a unique identifier. The sample project is on GitHub. The test creates 1000 objects, each with a unique identifier and (optionally) a video file of 165KB as binary data. By adding a data model version with a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,109,31,30,71],"class_list":["post-9270","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-coredata","tag-ios","tag-mac","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=9270"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9270\/revisions"}],"predecessor-version":[{"id":9271,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9270\/revisions\/9271"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=9270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=9270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=9270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}