Working with Embedded Swift for WebAssembly (for web app development) involves facing numerous limitations that seem unnecessary in the WebAssembly scenario.
String
String
is a significant component that adds megabytes to the final binary, which is why it has been removed. I created a custom String implementation with UTF-16 under the hood (code name U16String), as suggested by Max Desiatov. I am wondering if it is possible to implement StringInterpolation
for it, but it seems to be made at the compiler level only for String
.
Protocols
Cannot use a value of protocol any MyProtocol
type in Embedded Swift.
Protocols are partially functional. I assume that if full functionality were restored, the compiler would generate much more code to handle all possible cases. However, I don't think this would contribute significantly to the overall size in megabytes.
Codable
'Codable' is unavailable: unavailable in Embedded Swift.
Does it also add too much to the final binary? It would be great to have Encodable
and Decodable
protocols available, so custom encoders/decoders could be written.
Concurrency
Is it available in any form?
I understand these limitations from the perspective of microcontrollers where every kilobyte matters, and Embedded Swift was actually made for that.
For WebAssembly, it is also crucial to minimize the final binary size. My current wasm binary using Embedded Swift is under 150KB, which is impressive, especially compared to a full Swift implementation which is about 10-13MB. However, I believe that for WebAssembly, we still need a full version of Swift with the ability to disable large features like String
support to reduce the final binary size dramatically to about 1-2MB, while retaining most of Swift's powerful features.
For me, Swift for WebAssembly development is akin to development for iOS/tvOS/macOS targets—it is client-side code. It would be great to be able to reuse most components of client-side code across platforms. However, the absolute minimum is having models (codable structs), which seems impossible while Codable
is completely unavailable.