swift-aws-lambda-runtime icon indicating copy to clipboard operation
swift-aws-lambda-runtime copied to clipboard

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

Open darylteo opened this issue 2 years ago • 2 comments

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.

darylteo avatar Mar 22 '23 06:03 darylteo

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

sebsto avatar Apr 01 '23 13:04 sebsto

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.

Andrea-Scuderi avatar Apr 01 '23 13:04 Andrea-Scuderi

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

sebsto avatar May 13 '24 10:05 sebsto