swift-server / swift-aws-lambda-runtime

Swift implementation of AWS Lambda Runtime
Apache License 2.0
1.12k stars 101 forks source link

Totally remove dependency on Foundation #242

Closed stevapple closed 2 years ago

stevapple commented 2 years ago

ICU is going to be swapped out from stdlib, and statically linking it means that users can get a single portable executable. Meanwhile, Foundation still links against ICU, which makes it an extremely clumsy and heavy dependency.

Currently, we use Foundation in AWSLambdaRuntime for Date and Codable integration. The former one can be replaced by timestamp, and the latter one can be replaced by other Foundation-less implementation of JSONDecoder and JSONEncoder.

stevapple commented 2 years ago

I found swift-extras-json as some possible alternative, what do you think? @fabianfett

fabianfett commented 2 years ago

The swift-aws-lambda-runtime already supports a Foundation less mode today. You just need to import AWSLambdaRuntimeCore instead of AWSLambdaRuntime. AWSLambdaRuntimeCore does not depend on Foundation, and therefore has no own JSON encoding and decoding. You will need to bring your own JSON encoder and decoder in this case. swift-extras-json might be a good choice for that. 😉

However I doubt that we should make this the default case. Most Lambda runtime users, probably don't care at all about the minimal performance benefits you see when using an alternative json library. For those users the default Foundation implementation should just be there. Please keep in mind that alternative json libraries might have different behaviors around certain cases. For example: swift-extras-json does not have the special handling for Date and Data that users of the Foundation implementation might be expecting.

Given that we already support a Foundation less mode today, I think we can close this issue. WDYT? However we would be happy to accept PRs that improve the documentation around this.

A side not re swift-extras-json: The implementation has been lifted and shifted into Swift-Foundation with Swift 5.5, which has improved json performance significantly on Linux. However the issue with Swift-Foundation depending on icu remains.

fabianfett commented 2 years ago

@stevapple Do you think we can close this?