Introducing Lucet: Fastly’s Native WebAssembly Compiler and Runtime for Edge Computing
Lucet, an open‑source WebAssembly compiler and runtime from Fastly, enables fast, low‑overhead execution of WebAssembly modules at the edge by instantiating thousands of instances per second with minimal memory, supporting languages like Rust, C, and offering WASI integration for secure, portable workloads.
WebAssembly is a portable, size‑efficient format designed for compilation to the web, and edge computing is an emerging field where running workloads close to users can greatly improve performance and reduce overhead. This article explains how using WebAssembly as an edge‑computing container, via Fastly’s Lucet project, can significantly boost edge efficiency.
Lucet is Fastly’s open‑source WebAssembly compiler and runtime. While WebAssembly enables near‑native speed execution in browsers, Lucet moves execution outside the browser, allowing Fastly’s edge cloud to run WebAssembly modules faster and more securely. Languages such as Rust, TypeScript, C, and C++ already target WebAssembly, and more are being added.
A key design goal of Lucet is to launch a separate instance for each request, enabling tens of thousands of WebAssembly instances per second within a single process. Lucet can instantiate a module in about 50 µs using only a few kilobytes of memory, compared with Chromium’s V8 engine which needs roughly 5 ms and dozens of megabytes.
Security is enforced by the Lucet compiler and runtime, which ensure each WebAssembly program can only access its own resources, allowing developers to write code in familiar languages without compromising safety.
Lucet separates compilation and execution into two components: the lucetc compiler, which AOT‑compiles WebAssembly modules to native code, and the lucet-runtime , which loads the compiled shared objects, instantiates them, and calls exported functions. This AOT approach simplifies runtime design compared with JIT strategies used in browsers.
Lucet is built on the Cranelift code generator (originally created by Mozilla for Firefox). It supports the WebAssembly System Interface (WASI), a standard for exposing low‑level system resources (filesystem, network, etc.) safely to WebAssembly programs. Early Lucet versions were written in C; the current implementation is in Rust.
Component Overview
lucetc – the Lucet compiler that turns WebAssembly modules (.wasm or .wat) into native shared objects (.so).
lucet-runtime – a Rust crate (also usable as a C library) that loads the compiled shared objects, manages resources, and provides mechanisms for detecting and recovering from illegal operations.
lucet-wasi – provides WASI runtime support; it can be used as a library or as an executable to run WASI‑enabled WebAssembly programs compiled with lucetc .
Demo
Clone the Lucet repository:
git clone --recurse-submodules https://github.com/fastly/lucetSet up the development environment (Docker is recommended) and source the environment script:
$ cd lucet
$ source devenv_setenv.shCreate a simple C program and compile it to WebAssembly using the WASI‑targeted Clang:
#include
int main(int argc, char* argv[]) {
if (argc > 1) {
printf("Hello from Lucet, %s!\n", argv[1]);
} else {
puts("Hello, world!");
}
return 0;
}
$ wasm32-unknown-wasi-clang hello.c -o hello.wasmCompile the WebAssembly module to a native shared object with Lucet:
$ lucetc-wasi hello.wasm -o hello.soRun the native code using the Lucet runtime:
$ lucet-wasi hello.so Hello, world!
$ lucet-wasi hello.so world Hello from Lucet, world!The Lucet codebase also includes extensive documentation and additional examples. By open‑sourcing Lucet, Fastly expands the use cases for WebAssembly beyond browsers and edge clouds, enabling secure, low‑resource execution on any platform that supports scripting or extensions, whether in the cloud, at edge nodes, on laptops, or mobile devices.
High Availability Architecture
Official account for High Availability Architecture.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.