Universal webassembly runtime — wasmer 1.0 GA

Time:2021-5-6

Universal webassembly runtime -- wasmer 1.0 GA

Wasmer was the first to run on the server sideNginxWeb assembly (wasm) runtime of.

Using wasm for software containerization, we create a general binary file, which can run anywhere without modification, including Linux, MacOS, windows, web browser and other operating systems. By default, wasm automatically sandboxes applications for safe execution, thus protecting the host environment from malicious code, errors and vulnerabilities in the running software. Wasm also provides a lean execution environment that enables wasmer containers to run where docker containers are too heavy to work. I believe that webassembly will be the key component of software running and containerization in the future.

After more than two years of development, wasmer 1.0 GA, including the following future:

  • Production ready performance
  • Pluggable infrastructure
  • Native object engine
  • Headless wasmer: the ideal choice for Internet of things
  • Cross compiling
  • Super easy to use and extensible API
  • Wasm-c-api support
  • Error handling and debugging

Next, let’s talk about each future in depth!

Performance benchmark

Wasmer 1.0 performance benchmark needs to be released independently. Make a complete analysis of wasmer and other wasm runtimes, so that you can compare and choose the most suitable technology for your project!

Wasmer 1.0 compiles nine times faster

Now, all of our compilers can compile functions in parallel. With this new strategy, the compilation speed of all compilers is increased by 9 times.

Through the comparison of practical examples, these figures are easier to understand. Here, we can see the compilation time of clam.wasm in wasmer 0.17.1 and wasmer 1.0:

  • Singlepass: from 18s to 2s (9x speedup)
  • Cranelift: from 27s to 9s (3x speedup)
  • LLVM: from 1140s to 117s (9x speedup)

Pluggable infrastructure

Scalability is one of the most critical functions in any infrastructure product. One of our most important features is to support multiple compilers. Wasmer 1.0 comes with the following support:

  • Singlepass: for ultra fast compile time (block chain) not affected by JIT bonds
  • Cranelift: fast compilation with minimal optimization (ideal development approach)
  • LLVM: generate the best machine code when it must have the best performance (ideal production mode)

In addition to the compiler, we also introduced pluggable engine support. The web assembly engine is an abstraction that determines how the compiler manages the generated assembly code, including how to load and serialize it. Wasmer 1.0 supports the following compiler engines:

  • JIT engine: it pushes the generated code directly into memory
  • Native engine: it generates native code that can be loaded as a shared object. In addition, the execution and startup performance of the objects and modules shared by the native engine in just a few microseconds is incredible!

Native object engine

Wasmer 1.0 introduces “wasmer compile”, a new command for precompiling wasm files. Our customers and developers use “wasmer compile — native” to precompile webassembly modules into native object files, such as.so.dyliband.dll. Precompiled objects and modules are compatible with wasmer cli or used with wasmer embeddings (rust, python, go, etc.).

The core advantage of precompiling native objects is that they only need the least runtime to run the compiled modules, while still providing a complete sandbox environment. The compilation time is eliminated, and the artifacts can be executed directly at extremely fast startup time.

First run:

wasmer compile --native python.wasm -o python.so

For stand-alone execution, run:

wasmer run python.so

Or run embedded programs (rust example… Supports many other examples):

let module = Module::deserialize_from_file(“python.so”);
let instance = Instance::new(module, &wasi_imports);

Headless Wasmer

It’s no secret that edge running IOT devices are driving the future of computing. However, many devices lack the best computing hardware or other resources, such as power, network and storage. In the past, users included wasmer and all compilers in their wasm applications. This approach is not ideal, especially for Internet of things and edge computing use cases.
Universal webassembly runtime -- wasmer 1.0 GA
In wasmer 1.0, we see that wasm and wasmer are leading the way in providing as lightweight an execution environment as possible, which is crucial for running wasm efficiently on edge IOT devices. With our new support for AOT compilation, you can run the “headless” version of wasmer, which weighs only a few hundred KB, and you can run any precompiled wasm binary on any device.

Cross compiling

Wasmer 1.0 now has cross compiling capabilities. In previous versions of wasmer, native compiled wasm applications were targeted and run on the same architecture. With wasmer 1.0, you canx86_64The machine isaarch64Architecture precompile wasm and vice versa.

In anyx86_64Running on the machine:

wasmer compile python.wasm -o python-arm.so --native --target=aarch64-linux-gnu

Then run the compilation result locally on your arm machine

wasmer run python-arm.so

Very easy to use API

Universal webassembly runtime -- wasmer 1.0 GA
The main goal of wasmer 1.0 is to make it easy for developers with limited knowledge of advanced webassembly concepts or webassembly ecosystems to use APIs. Wasmer 1.0 further improves our API by adjusting it according to the similar structure of the standard wasm-c-api to make it more flexible in the future.

use wasmer::{Store, Module, Instance, Value, imports};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let module_wat = r#"
    (module
    (type $t0 (func (param i32) (result i32)))
    (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
        get_local $p0
        i32.const 1
        i32.add))
    "#;
    
    let store = Store::default();
    let module = Module::new(&store, &module_wat);
    let import_object = imports! {};
    let instance = Instance::new(module, &import_object)?;

    let add_one = instance.exports.get_function("add_one")?;
    let result = add_one.call([Value::I32(42)])?;
    assert_eq!(result[0], Value::I32(43));

    Ok(())
}

Wasm-C-API

With the maturity of webassembly ecosystem, the industry will correctly promote and unify the API for interaction with webassembly. Wasm-c-api is relatively new, so we decided to build an API that closely matches the internal structure.

However, as the industry moved towards a common API, we decided to make it part of wasmer 1.0 and contribute so that everyone could benefit from it.

Note: we will continue to support wasmer-c-api. However, we recommend that current users switch to the standard wasm-c-api.

Error handling and debugging

Wasmer 1.0 completely redefines and provides new and improved error handling capabilities, so that developers can safely integrate with wasmer. It greatly reduces the time required to build a wasm application that can be put into production. For example, every time an error occurs, you need to know exactly where the error originated: is it from a virtual machine? Is it because there are not enough available resources? Or is it just the expected error triggered by some native functions? Wasmer 1.0 lays the foundation for more advanced error detection and reporting in the future.

Support for Apple silicon

Just a few weeks ago, Apple launched its new line of computers with a new arm based chipset: Apple silicon.

Arm in server-side workload has a bright future, which consolidates the demand for universal binary files across chipsets. We are very pleased to announce that wasmer is the first service to support wasm in Apple silicon.

on trial

If you want to try wasmer, you can start fromwasmer.ioInstall the CLI to run wasmer independently or embed it in your favorite programming language.

Recommended Today

Looking for frustration 1.0

I believe you have a basic understanding of trust in yesterday’s article. Today we will give a complete introduction to trust. Why choose rust It’s a language that gives everyone the ability to build reliable and efficient software. You can’t write unsafe code here (unsafe block is not in the scope of discussion). Most of […]