swift-server / swift-aws-lambda-runtime

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

[Idea] Could Lambda Layers Custom Runtime improve cold start performance? #295

Closed darylteo closed 1 month ago

darylteo commented 1 year ago

Swift provides great Unicode support via ICU. Therefore, Swift-based Lambda functions include the ICU libraries which tend to be large. This impacts the download time mentioned above and an area for further optimization. Some of the alternatives worth exploring are using the system ICU that comes with Amazon Linux (albeit older than the one Swift ships with) or working to remove the ICU dependency altogether. We welcome ideas and contributions to this end.

Could this be potentially solved by supporting a Lambda Layer that comes with the latest ICU libraries (and other runtime libs) that a Swift binary could link to, to reduce the zip size of the actual lambda itself?

https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path

It could also be interesting to evaluate the cold start performance of upload pre-compiled vs uploading scripts for compiling, if all the tools for Swift is bundled as a custom Runtime instead... and also remove the requirement of Docker for deployment.

sebsto commented 1 year ago

We recently discussed options on the Swift Server Side slack https://swift-open-source.slack.com/archives/C5GMX4LP9/p1678653994596389

TL;DR : Lambda Layers should work (@Andrea-Scuderi has a working example)

About compiling at first execution. I don't think it is a good idea. Cold startup time will be terrible (several minutes depending on the number of dependencies and the size of your project) and you will have to install the Swift toolchain in the Lambda runtime anyway .... so even more Docker

Andrea-Scuderi commented 1 year ago

Yes, you can see the example here, but I removed the layers from the master branch as the deployment process is more difficult. The cons of the Layer is that you need to prepare the layers and the code from the same Docker builder environment.

sebsto commented 1 month ago

@darylteo There is no more traffic since 1 year, I think the question has been answered. Can we close this ?