Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Fermyon Spin 2.0 Adds Support for WebAssembly Components and WASI Preview 2

Fermyon Spin 2.0 Adds Support for WebAssembly Components and WASI Preview 2

Spin 2.0, an open-source tool to build and run serverless WebAssembly apps, gets support for WebAssembly components, improves performance and developer experience, and lays the foundation for Wasm portability across runtimes and implementations.

Spin has been using WebAssembly components under the hood since version 1.5. In version 2.0, you can leverage all properties supported by Wasm components, including the possibility of composing components created using any language supporting Wasm.

With the Component Model a component written in JavaScript can import a high-performance component written in Rust, or another written in Python, and they can communicate and exchange data in a portable way, without needing to be aware of the language, or any other implementation details, of each other.

For example, a component can be created using a high-performance, memory-safe language like Rust, and composed with another component written in, e.g., Python using wasm-tools compose, which will generate a new component usable in Spin 2.0. The key for this composition to work is defining a common interface across the composed components using the Wasm Interface Type to define a contract or targeting a known WebAssembly interface.

To improve performance, Spin 2.0 adopts Wasmtime’s pooling memory allocator and several others improvements, which increase Spin throughput by up to an order of magnitude, says Fermyon. This enables Spin 2.0 to provide fast startup times for WebAssembly components and create a new instance for every request to improve security.

That means that even in case an attacker can exploit a flaw in the application to corrupt its state, that corruption will only last for the current request, instead of affecting all future requests processed on the same machine.

As Matei Radu explained on Hacker News, this is the only instantiation model currently supported by Spin 2.0, but nothing prevents developers from implementing a different trigger to have, e.g, long-running processes.

Spin 2.0 also implements experimental support for streaming HTTP responses, built on top of WASI preview 2 and WASI HTTP. This makes it possible for a component to start sending its response as soon as it starts becoming available.

While the WebAssembly component model is fairly stable, WASI Preview 2 is still under active development. To make it easier for developers to adapt to changes in WASI Preview 2, Fermyon will leverage the fact that component interfaces are versioned to support multiple snapshots of WASI Preview 2, so that existing components can continue working and newer ones can adopt new WASI Preview 2 features.

About the Author

Rate this Article