{"id":8412,"date":"2014-01-31T17:42:36","date_gmt":"2014-01-31T22:42:36","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=8412"},"modified":"2014-01-31T17:42:36","modified_gmt":"2014-01-31T22:42:36","slug":"arcs-fast-autorelease","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/01\/31\/arcs-fast-autorelease\/","title":{"rendered":"ARC&rsquo;s Fast Autorelease"},"content":{"rendered":"<p><a href=\"http:\/\/rentzsch.tumblr.com\/post\/75082194868\/arcs-fast-autorelease\">Wolf Rentzsch<\/a>:<\/p>\n<blockquote cite=\"http:\/\/rentzsch.tumblr.com\/post\/75082194868\/arcs-fast-autorelease\"><p>ARC has a trick that keep returned objects out of autorelease pools if both the caller and callee are ARC.<\/p><\/blockquote>\n<p>This has been well advertised, but he links to the relevant <a href=\"http:\/\/opensource.apple.com\/source\/objc4\/objc4-532.2\/runtime\/NSObject.mm\">runtime source code<\/a>:<\/p>\n<blockquote cite=\"http:\/\/rentzsch.tumblr.com\/post\/75082194868\/arcs-fast-autorelease\"><p>To summarize, <code>callerAcceptsFastAutorelease()<\/code> <em>inspects the caller&rsquo;s instructions<\/em> and uses it to determine <em>at runtime<\/em> whether it needs to actually put the returned object in the autorelease pool or if it&rsquo;s on the same ARC-team and it can be skipped (speeding things up).<\/p><\/blockquote>\n<p>The related Twitter conversation also revealed some interesting details. For example, the autorelease pool optimization initially <a href=\"https:\/\/twitter.com\/Catfish_Man\/status\/428996803493519360\">did not work<\/a> for <code>+[NSDate date]<\/code>. Its implementation calls <code>gettimeofday()<\/code>, and <a href=\"https:\/\/twitter.com\/Catfish_Man\/status\/429012501087281152\">something about this<\/a> confused Clang&rsquo;s optimizer <a href=\"https:\/\/twitter.com\/Catfish_Man\/status\/428999685659828224\">so that<\/a> it did not generate a <a href=\"https:\/\/twitter.com\/gparker\/status\/429016708943073281\">tail call<\/a>, <a href=\"https:\/\/twitter.com\/Catfish_Man\/status\/429010174087401472\">without which<\/a> the ARC optimization can&rsquo;t work.<\/p>","protected":false},"excerpt":{"rendered":"<p>Wolf Rentzsch: ARC has a trick that keep returned objects out of autorelease pools if both the caller and callee are ARC. This has been well advertised, but he links to the relevant runtime source code: To summarize, callerAcceptsFastAutorelease() inspects the caller&rsquo;s instructions and uses it to determine at runtime whether it needs to actually [&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":[55,230,255,571,54,74,138,71],"class_list":["post-8412","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-arc","tag-clang","tag-compiler","tag-memory-management","tag-objective-c","tag-opensource","tag-optimization","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8412","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=8412"}],"version-history":[{"count":0,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8412\/revisions"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=8412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=8412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=8412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}