{"id":13156,"date":"2015-12-20T14:19:05","date_gmt":"2015-12-20T19:19:05","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13156"},"modified":"2015-12-20T14:19:05","modified_gmt":"2015-12-20T19:19:05","slug":"core-data-threading-demystified","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/12\/20\/core-data-threading-demystified\/","title":{"rendered":"Core Data Threading Demystified"},"content":{"rendered":"<p><a href=\"https:\/\/realm.io\/news\/marcus-zarra-core-data-threading\/\">Marcus Zarra<\/a> (<a href=\"https:\/\/news.ycombinator.com\/item?id=10755904\">comments<\/a>):<\/p>\n<blockquote cite=\"https:\/\/realm.io\/news\/marcus-zarra-core-data-threading\/\">\n<p>In the best way, we go back to having one PSC, but we&rsquo;re going to use the new APIs in iOS 6. We&rsquo;re going to add a private MOC that talks to that PSC. Then, we&rsquo;re going to add our main context and define it as a main context, and we&rsquo;re going to make that a child of that private MOC. Any data processing will be below the main MOC, so we will have three levels of contexts.<\/p>\n<p>[&#8230;]<\/p>\n<p>This design allows us to have asynchronous saves, which is extremely important. It allows us to save and to consume or process data without blocking the UI. A user can happily scroll through our application, look at data, play with it, and we&rsquo;re not telling them that they have to wait for us.<\/p>\n<p>[&#8230;]<\/p>\n<p>We have an extra level of indirection between the PSC and the main MOC, so we will get a little bit of slowness there. When I say little bit, I mean if I build up a test case it does thousands upon thousands of iterations, I will find a 1-2% variance in the speed.<\/p>\n<p>[&#8230;]<\/p>\n<p>You can use notifications to force one child to consume updates from the other child, but don&rsquo;t do this. It&rsquo;s just a bad idea.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Marcus Zarra (comments): In the best way, we go back to having one PSC, but we&rsquo;re going to use the new APIs in iOS 6. We&rsquo;re going to add a private MOC that talks to that PSC. Then, we&rsquo;re going to add our main context and define it as a main context, and we&rsquo;re going [&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":[800,109,31,1137,30,1199,71],"class_list":["post-13156","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-concurrency","tag-coredata","tag-ios","tag-ios-9","tag-mac","tag-mac-os-x-10-11","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13156","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=13156"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13156\/revisions"}],"predecessor-version":[{"id":13157,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13156\/revisions\/13157"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}