{"id":37874,"date":"2022-12-12T15:46:57","date_gmt":"2022-12-12T20:46:57","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=37874"},"modified":"2025-10-29T09:37:58","modified_gmt":"2025-10-29T13:37:58","slug":"the-swifty-future-of-foundation","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/12\/12\/the-swifty-future-of-foundation\/","title":{"rendered":"The Swifty Future of Foundation"},"content":{"rendered":"<p><a href=\"https:\/\/www.swift.org\/blog\/future-of-foundation\/\">Tony Parker<\/a> (<a href=\"https:\/\/twitter.com\/SwiftLang\/status\/1601253728094674944\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/www.swift.org\/blog\/future-of-foundation\/\">\n<p>The <a href=\"https:\/\/github.com\/apple\/swift-corelibs-foundation\">swift-corelibs-foundation<\/a> project helped launch the open source Swift version of Foundation in 2016, wrapping a Swift layer around the preexisting, open source C implementation of Foundation.<\/p>\n<p>[&#8230;]<\/p>\n<p>Today, we are announcing a new open source Foundation project, written in Swift, for Swift.<\/p>\n<p>[&#8230;]<\/p>\n<p>With a native Swift implementation of Foundation, the framework no longer pays conversion costs between C and Swift, resulting in faster performance.<\/p>\n<p>[&#8230;]<\/p>\n<p>Multiple implementations of any API risks divergent behavior and ultimately bugs when moving code across platforms. This new Foundation package will serve as the core of a single, canonical implementation of Foundation, regardless of platform.<\/p>\n<p>[&#8230;]<\/p>\n<p>Open source projects are at their best when the community of users can participate and become a community of developers. A new, open contribution process will be available to enable all developers to contribute new API to Foundation.<\/p>\n<\/blockquote>\n\n<p>This sounds great. My understanding is that Foundation started as Objective-C and was re-written for Mac OS X to wrap Core Foundation, where possible&mdash;much like swift-corelibs-foundation wraps CF in Swift. This added some overhead but unified the implementations. Since then, Foundation has been rewritten back into Objective-C, which made it faster. Now, it sounds like the plan is to rewrite it in Swift and extend Swift to <a href=\"https:\/\/forums.swift.org\/t\/pitch-objective-c-implementations-in-swift\/61907\">allow Objective-C<\/a> to call the Swift implementation of the old API.<\/p>\n\n<p><a href=\"https:\/\/forums.swift.org\/t\/what-s-next-for-foundation\/61939\/31\">Tony Parker<\/a>:<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/what-s-next-for-foundation\/61939\/31\"><p>We&rsquo;ve prototyped this approach and are pretty sure it will work out well. A reimplementation of <code>Calendar<\/code> in Swift is 1.5x to 18x as fast as the C one (calling from Swift in various synthetic benchmarks like creation, date calculation). And it&rsquo;s completely compatible with the existing C and ObjC entry points, too.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/cohost.org\/Catfish-Man\/post\/557578-i-sup-with-a-lot-of\">David Smith<\/a>:<\/p>\n<blockquote cite=\"https:\/\/cohost.org\/Catfish-Man\/post\/557578-i-sup-with-a-lot-of\">\n<p>This means that now<\/p>\n<ul>\n<li>Foundation has the option to use a memory safe language internally<\/li>\n<li>Most system components that Foundation depends on have the option to use a memory safe language internally<\/li>\n<li>Embedded environments like the Secure Enclave can use Swift<\/li>\n<li>Pure-Swift processes use less memory<\/li>\n<li>Swift Strings use less memory and are faster<\/li>\n<li>Swift WebAssembly programs can be much smaller to download<\/li>\n<li>NSString&lt;-&gt;String bridging can use Foundation\/CoreFoundation internals directly, resulting in some speedups<\/li>\n<\/ul>\n<\/blockquote>\n\n<p><a href=\"https:\/\/forums.swift.org\/t\/what-s-next-for-foundation\/61939\">Tony Parker<\/a>:<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/what-s-next-for-foundation\/61939\">\n<p>Many of Foundation&rsquo;s features have been subsumed by direct support in the language. These types are currently not planned to be brought forward into the new package[&#8230;] On Darwin, the Foundation framework will continue to maintain implementations for these types in a combination of C, Objective-C and Swift.<\/p>\n<\/blockquote>\n<p>It&rsquo;s seems somewhat undetermined what the plan is for functionality in the old types that is not available elsewhere.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2015\/12\/03\/apple-open-sources-swift\/\">Apple Open Sources Swift<\/a><\/li>\n<\/ul>\n\n<p id=\"the-swifty-future-of-foundation-update-2023-01-12\">Update (2023-01-12): See also: <a href=\"https:\/\/www.infoq.com\/news\/2022\/12\/apple-swift-foundation-rewrite\/\">Sergio De Simone<\/a> (via <a href=\"https:\/\/news.ycombinator.com\/item?id=34339153\">Hacker News<\/a>).<\/p>","protected":false},"excerpt":{"rendered":"<p>Tony Parker (tweet): The swift-corelibs-foundation project helped launch the open source Swift version of Foundation in 2016, wrapping a Swift layer around the preexisting, open source C implementation of Foundation. [&#8230;] Today, we are announcing a new open source Foundation project, written in Swift, for Swift. [&#8230;] With a native Swift implementation of Foundation, the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2022-12-12T20:46:59Z","apple_news_api_id":"23fa874d-789a-450a-ab1b-af410cccc7f2","apple_news_api_modified_at":"2025-10-29T13:38:00Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAw==","apple_news_api_share_url":"https:\/\/apple.news\/AI_qHTXiaRQqrG69BDMzH8g","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,31,448,30,74,138,71,2854,901,1227,1231],"class_list":["post-37874","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-ios","tag-linux","tag-mac","tag-opensource","tag-optimization","tag-programming","tag-swift-foundation","tag-swift-programming-language","tag-top-posts","tag-webassembly"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/37874","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=37874"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/37874\/revisions"}],"predecessor-version":[{"id":38121,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/37874\/revisions\/38121"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=37874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=37874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=37874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}