Hello again Swift Community! I’ve got some news about the New Codable work I’ve been posting about in “New Codable” prototype available for feedback: it now has a new name, and its own official repository, independent from swift-foundation, called swiftlang/swift-serialization (GitHub - swiftlang/swift-serialization · GitHub).
For those not familiar, this project exists to satisfy the demonstrable need for an alternative to Codable that has the following qualities:
- More efficient in CPU and memory usage than
Codable - Compatible with Embedded Swift
- Provides code generation via macros with improved customization options and less need to write manual implementations
- Enables format-specific interfaces instead of forcing a limited set of primitive data types
For the initial version, 0.0.1, the code from Foundation’s experimental/new-codable branch has been imported as-is, complete with commit history. Some notes:
- The library has no dependency on Foundation. It needs only the standard library, swift-collections, and swift-syntax for the macros.
- It requires Swift 6.4 or later, and OS 27 on Apple platforms.
- We intend to support a wide range of platforms and environments, including Darwin, Linux, Windows, Android, WebAssembly, and Embedded Swift.
- There is now a separate Benchmarks package, built on package-benchmark, which currently compares the new JSON implementation against Foundation’s
JSONEncoderandJSONDecoder.
To try it out, add it as a package dependency:
.package(
url: "https://github.com/swiftlang/swift-serialization.git",
.upToNextMinor(from: "0.0.1")
)
Then add the dependency to your target:
.target(
name: "MyTarget",
dependencies: [
.product(name: "NewCodable", package: "swift-serialization")
]
)
For the moment, the module is still called NewCodable (and NewCodableMacros). I plan to rename these in 0.1.0, so please expect that.
Since this package doesn’t depend on Foundation in any way, the Date and Data conformances and other Foundation-specific features that were available on the experimental/new-codable branch are not included. These will return some time in the future, either by making swift-foundation depend on swift-serialization, or via some other package.
Please excuse our dust. This is very much a work in progress. We welcome your pull requests to get the project into shape. I've already begun the process of proposing some major naming changes to align with the "swift-serialization" nomenclature, as well as some big API improvements.
Your time, consideration, and feedback are greatly appreciated, and are in fact critical to this project’s success. We hope the new dedicated repository will facilitate adoption, experimentation, discussion, and evolution of these APIs.
Thank you!