AWS Lambda SnapStart - Part 9 Measuring Java 21 Lambda cold starts
Tags: java, aws, serverless, coldstart
Published: 2023-11-20 16:21:42

## Introduction
In the [part 7](https://dev.to/aws-builders/measuring-java-11-lambda-cold-starts-with-snapstart-part-7-re-measuring-5gn6) of our series we re-measured the cold start of the Lambda function with Corretto Java 11 runtime and SnapStart enabled after AWS fixed the "Restore Duration" time displayed in the CloudWatch (Logs). You can refer to the part 7 to review the results of our measurements. 

In [part 8](https://dev.to/aws-builders/measuring-lambda-cold-starts-with-aws-snapstart-part-8-measuring-with-java-17-21db) we measured the cold start of the Lambda function with Corretto Java 17 runtime and SnapStart enabled .

On November 17 AWS announced support of [Corretto Java 21 runtime](https://aws.amazon.com/de/about-aws/whats-new/2023/11/aws-lambda-support-java-21/) for Lambda.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1z08qsu54tn1ccmpsce0.png)

This a very good sign to the Java community that the support of the LTS version comes less than 2 months after this long term release is there. We had to wait for Lambda support of Java 17 way too long :)

SnapStart is also supported with Java 21 directly from the beginning  (in the supported regions). I was curious what cold starts we will get with Java 21 with SnapStart enabled and also with and without the usage of priming. So let's measure it.

## Measuring the cold start times with Java 21 with and without SnapStart enabled

For measurement purposes I created/copied the [sample application](https://github.com/Vadym79/AWSLambdaJavaSnapStart/tree/main/pure-lambda-21) and configured Lambda functions to use Java 21 runtime for Lambda and 1024 MB memory .

Now we use the same CloudWatch Logs Insights Query as we used in the [part 7 of our series](https://dev.to/aws-builders/measuring-java-11-lambda-cold-starts-with-snapstart-part-7-re-measuring-5gn6). We also enable SnapStart for both our Lambda functions  GetProductByIdWithPureJava21Lambda (without priming) and GetProductByIdWithPureJava21LambdaAndPriming (with priming of DynamoDB invocation) and after approximately 100 cold starts we got the following durations:

| Experiment description                   | p50      | p90       |p99       |
|---------------------------  |----------|-----------|----------|
|cold start time w/o SnapSart                | 3155.88  | 3292.80   | 3605.95  |
|cold start time with SnapStart w/o Priming  | 1591.31  | 1823.14   | 2021.67  |
|cold start time with SnapStart with Priming | 760.79   | 955.76    | 1200.12  |

## Conclusion
For the cold start times measured with Java 11, 17 and 21 runtimes with SnapStart enabled and additionally with and without priming of DynamoDB invocation we got comparable results, but Java 21 measurements had slightly worse results for p90 and p99 especially when using priming. This may depend on the executed measurements. 

I also refer to my previous article [Reducing Cold Starts on AWS Lambda with Java Runtime - Future Ideas about SnapStart, GraalVM and Co ](https://dev.to/aws-builders/reducing-cold-starts-on-aws-lambda-with-java-runtime-future-ideas-about-snapstart-graalvm-and-co-3a1b). I think it's now time for AWS to provide some improvements and to further reduce the cold start duration with SnapStart.