{"id":17247,"date":"2017-02-18T19:37:43","date_gmt":"2017-02-19T00:37:43","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=17247"},"modified":"2020-04-21T13:59:52","modified_gmt":"2020-04-21T17:59:52","slug":"swift-ownership-manifesto","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/02\/18\/swift-ownership-manifesto\/","title":{"rendered":"Swift Ownership Manifesto"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/apple\/swift\/blob\/master\/docs\/OwnershipManifesto.md\">Apple<\/a> (<a href=\"https:\/\/forums.swift.org\/t\/manifesto-ownership\/5212\">mailing list<\/a>):<\/p>\n<blockquote cite=\"https:\/\/github.com\/apple\/swift\/blob\/master\/docs\/OwnershipManifesto.md\"><p>The widespread use of copy-on-write value types in Swift has generally\nbeen a success.  It does, however, come with some drawbacks:<\/p><ul><li><p>Reference counting and uniqueness testing do impose some overhead.<\/p><\/li><li><p>Reference counting provides deterministic performance in most cases,\nbut that performance can still be complex to analyze and predict.<\/p><\/li><li><p>The ability to copy a value at any time and thus &ldquo;escape&rdquo; it forces\nthe underlying buffers to generally be heap-allocated.  Stack allocation\nis far more efficient but does require some ability to prevent, or at\nleast recognize, attempts to escape the value.<\/p><\/li><\/ul><p>Certain kinds of low-level programming require stricter performance\nguarantees.  Often these guarantees are less about absolute performance\nthan <em>predictable<\/em> performance.  For example, keeping up with an audio\nstream is not a taxing job for a modern processor, even with significant\nper-sample overheads, but any sort of unexpected hiccup is immediately\nnoticeable by users.<\/p><p>Another common programming task is to optimize existing code when something\nabout it falls short of a performance target.  Often this means finding\n&rdquo;hot spots&rdquo; in execution time or memory use and trying to fix them in some\nway.  When those hot spots are due to implicit copies, Swift&rsquo;s current\ntools for fixing the problem are relatively poor; for example, a programmer\ncan fall back on using unsafe pointers, but this loses a lot of the\nsafety benefits and expressivity advantages of the library collection types.<\/p><p>We believe that these problems can be addressed with an opt-in set of\nfeatures that we collectively call <em>ownership<\/em>.<\/p><\/blockquote>\n<p>Previously: <a href=\"http:\/\/mjtsai.com\/blog\/2017\/01\/23\/chris-lattner-atp-interview\/\">Chris Lattner ATP Interview<\/a>, <a href=\"http:\/\/mjtsai.com\/blog\/2015\/12\/09\/swift-plans\/\">Swift Plans<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Apple (mailing list): The widespread use of copy-on-write value types in Swift has generally been a success. It does, however, come with some drawbacks:Reference counting and uniqueness testing do impose some overhead.Reference counting provides deterministic performance in most cases, but that performance can still be complex to analyze and predict.The ability to copy a value [&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":"2020-04-21T17:59:56Z","apple_news_api_id":"38874250-6d16-4b9b-988b-dc9273058dc6","apple_news_api_modified_at":"2020-04-21T17:59:56Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AOIdCUG0WS5uYi9yScwWNxg","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,46,571,138,71,901],"class_list":["post-17247","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-arc","tag-languagedesign","tag-memory-management","tag-optimization","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17247","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=17247"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17247\/revisions"}],"predecessor-version":[{"id":28734,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17247\/revisions\/28734"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=17247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=17247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=17247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}