The Swift team has begun work on an open-source implementation of the open-source Foundation framework. Written entirely in Swift, the new Foundation aims to improve performance by getting rid of the conversion overhead between Objective-C and Swift, as well as providing the ability to modularize and clean up.

In this way, a number of technical goals are achieved:

  • No more packaged C code. With the native Swift implementation of the Foundation framework, it no longer pays conversion costs between C and Swift, resulting in faster performance. The Swift implementation, developed as a package, also makes it easier for Swift developers to inspect, understand, and contribute code.
  • Enable smaller, more detailed packages. Rewriting Foundation provides an opportunity to tailor its architecture to evolving use cases. Developers want to keep their binaries small, and the new FoundationEssentials package will provide the most important types in Foundation without system dependencies to help achieve this goal. A separate FoundationInternationalization package will be available when you need to work with localized content, such as formatted dates and times. Other packages will continue to provide XML and networking support. A new FoundationObjCCompatibility package will contain legacy APIs that are useful for some applications.
  • Merging Foundation implementations. Multiple implementations of each API risk different behavior and ultimately errors when moving code to different platforms. This new Foundation package will serve as the core of a single, canonical implementation of Foundation, regardless of platform.

“With a native Swift implementation of Foundation, the framework no longer pays conversion costs between C and Swift, resulting in faster performance. Calendar reimplementation in Swift is 1.5 to 18 times faster than in C (calling from Swift in various synthetic benchmarks such as create, calculate date).”

As Apple engineer Tony Parker explained in the Swift forum, the performance benefit can be significant:

The Foundation framework is a cornerstone of most macOS and iOS apps, providing a large number of ubiquitous abstractions, including NSObject, NSString, NSArray, and NSDictionary, among many others.

 

Tags: , , , , , , , , , , , , , ,
Editor @ DevStyleR