First impressions of the fastest JavaScript runtime for Lambda
Tags: aws, javascript, lambda, serverless
Published: 2024-02-28 01:08:02

---
title: First impressions of the fastest JavaScript runtime for Lambda
published: true
date: 2024-02-27 12:27:10 UTC
tags: AWS,Javascript,Lambda,Serverless
canonical_url: https://theburningmonk.com/2024/02/first-impressions-of-the-fastest-javascript-runtime-for-lambda/
---

I thought Lambda needed a specialised runtime. One that works well with its resource-constraint execution environment. I even [floated a few ideas](https://twitter.com/theburningmonk/status/1202290912853757952) in the past but sadly I don’t have the chops to make them happen myself.

[![](https://theburningmonk.com/wp-content/uploads/2024/02/img_65ddce8289e7b.png)](https://twitter.com/theburningmonk/status/1202290912853757952)

So I was pleasantly surprised when AWS open-sourced the [LLRT runtime for JavaScript](https://github.com/awslabs/llrt) [1]!

### What is LLRT?

LLRT, or Low Latency Runtime, is a new and experimental JavaScript runtime for Lambda. It promises 10x faster startup time. Which should significantly help with the dreaded Lambda cold starts.

![](https://theburningmonk.com/wp-content/uploads/2024/02/img_65ddcf24e3085.png)

Naturally, I had to test it out for myself and see if the hype was real.

### My first impressions of LLRT

In my limited tests, the `init duration` for a simple function went from ~750ms to 55ms. Which was very impressive! The function under test only uses the DynamoDB client from the AWS SDK v3 and makes one request to DynamoDB.

Along the way, I also discovered several limitations:

- It only supports ESM modules.
- It doesn’t work with the popular [middy](https://github.com/middyjs/middy) [2] middelware engine. Because LLRT hasn’t implemented the `node:stream` API. See the [API compatibility](https://github.com/awslabs/llrt/blob/main/API.md) [3] page for the list of supported APIs.
- It doesn’t work with the [Lambda Powertools](https://docs.powertools.aws.dev/lambda/typescript/latest/) [4]. Because the LLRT doesn’t allow importing the `node:console` method in userland. See Andrea Amorosi’s response [here](https://twitter.com/dreamorosi/status/1760575292937015431) for more details.

LLRT is not ready for prime time yet. And given that it’s been in the works for almost two years, we should set expectations accordingly.

It’s probably not going to be production-ready in the coming months. But the potential is there and I’m really excited about it!

For one thing, it might finally stop people talking about cold starts. As I [said on LinkedIn](https://www.linkedin.com/posts/theburningmonk_aws-serverless-awslambda-activity-7167986688810541056-nwK7/?utm_source=share&utm_medium=member_desktop) [5] yesterday, most people are overthinking about Lambda cold starts. If you’re not sure if Lambda cold starts is likely a problem for you, then go read the LinkedIn post and come back here.

![](https://theburningmonk.com/wp-content/uploads/2024/02/img_65ddd02f5d8b6.png)

Back to LLRT.

I later spoke with [Richard Davison](https://www.linkedin.com/in/richard-davison-992462101/), the creator of the LLRT project.

I wanted to learn more about the project and the design decisions behind it.

What made it start so much faster?

What trade-offs did they make?

LLRT is the answer to the question “What would a purposely built JavaScript runtime look like for Lambda.”

A lot of people see that “It’s built in Rust” and automatically assume that’s why it’s fast. But it’s more than that.

When it comes to performance optimizations, it always boils down to what you let go. If you choose to do everything the incumbent does, then you won’t make any significant performance gains.

### No JIT compilation

With LLRT, they chose to not include a JIT compiler. Because it’s focused on Lambda’s **resource constraint and short-lived** execution environments.

As a result, LLRT is likely less performant than the Node.js runtime for CPU-intensive tasks.

However, most Lambda functions do not perform CPU-intensive tasks. Instead, they tend to be IO-intensive.

And the Lambda execution environments are short-lived. So a JIT compiler would have been less effective at optimizing hot code paths.

At the same time, a JIT compiler comes with significant startup costs. It also introduces occasional latency spikes when it needs to evict cached items.

So it appears a sensible trade-off for LLRT to not include a JIT compiler.

### QuickJs + Rust

The [QuickJs engine](https://bellard.org/quickjs/quickjs.html) [6] plays a crucial role in LLRT and its outstanding performance. Another reason why LLRT is fast is because they wrote all the APIs in Rust.

As much as possible, the team wants to stay in native code to guarantee a strong performance. [Bun](https://bun.sh/) [7] took the same approach and implemented all the APIs in a system language called [Zig](https://ziglang.org/) [8].

The downside to this approach is that it’s harder for contributors to get in on the action. There are a lot fewer Rust developers than Node.js developers. And even fewer Rust developers who are interested in a JavaScript runtime.

### LLRT vs Bun (and other JS runtimes)

LLRT is different from other JavaScript runtimes. It’s not a general-purpose runtime for JavaScript. It doesn’t have to worry about running in the browser or on mobile phones.

Instead, it’s solely focused on the Lambda execution environment.

This allows them to make decisions that just wouldn’t make sense with Bun or Node.js. Decisions such as not including a JIT compiler. Or which of the JavaScript APIs do they implement first, or at all?

The goal is to eventually become [WinterCG](https://wintercg.org/) compliant. But we don’t have to wait for that to start using LLRT. For LLRT to be useful (but not perfect!), it just needs to support the AWS SDK and a few popular libraries.

### Summary

To summarize, LLRT is an exciting new runtime for JavaScript.

It’s purposely built for Lambda.

It’s not intended as a general-purpose runtime for JavaScript.

It makes design trade-offs (such as not having a JIT compiler) to achieve an optimal cold start time.

It uses the QuickJs engine and implements all the JavaScript APIs in Rust.

To learn more about LLRT and how to contribute to it, please check out [my conversation with Richard on YouTube](https://youtu.be/XQism0mZ4pE) [9].

I will be covering LLRT in my upcoming workshop, including how to use it with the Serverless Framework and CDK. If you wanna take your serverless game to the next level, then you should check it out! More information is available on the [course page](https://productionreadyserverless.com/?utm_campaign=llrt-first-impressions&utm_source=blog) [10].

[![](https://theburningmonk.com/wp-content/uploads/2023/12/prsls-in-4-weeks.jpeg)](https://productionreadyserverless.com/?utm_campaign=llrt-first-impressions&utm_source=blog&utm_content=image)

 

### Links

[1] [GitHub repo for LLRT](https://github.com/awslabs/llrt)

[2] [Middy middleware engine](https://github.com/middyjs/middy)

[3] [LLRT’s API compatibility page](https://github.com/awslabs/llrt/blob/main/API.md)

[4] [AWS Lambda Powertools for TypeScript](https://docs.powertools.aws.dev/lambda/typescript/latest/)

[5] [Most people are overthinking about Lambda cold starts](https://www.linkedin.com/posts/theburningmonk_aws-serverless-awslambda-activity-7167986688810541056-nwK7/?utm_source=share&utm_medium=member_desktop)

[6] [QuickJs engine](https://bellard.org/quickjs/quickjs.html)

[7] [The Bun runtime for JavaScript](https://bun.sh/)

[8] [The Zip programming language](https://ziglang.org/)

[9] [My interview with Richard Davison, the creator of LLRT](https://www.youtube.com/watch?v=XQism0mZ4pE)

[10] [Production-Ready Serverless workshop](https://productionreadyserverless.com/?utm_campaign=llrt-first-impressions&utm_source=blog)

The post [First impressions of the fastest JavaScript runtime for Lambda](https://theburningmonk.com/2024/02/first-impressions-of-the-fastest-javascript-runtime-for-lambda/) appeared first on [theburningmonk.com](https://theburningmonk.com).