HNHacker News
TopNewBestAskShowJobs

phickey

803 karma · joined November 20, 2018

https://moreproductive.org github.com/pchickey pat@moreproductive.org

I am a maintainer for Wasmtime and work on many related projects: * Sr Principal Engineer at F5, working on WebAssembly (2024-) * former Co-chair of the WebAssembly CG's WASI Subgroup (2023-2025) * At-large Director on the Bytecode Alliance Board (2024-2025 term).

submissionscomments
phickey··on Libc++ 9.0.0 adds explicit support for WASI
Its an evolving standard set of system interfaces. Right now it supports sandboxed access to the filesystem via a POSIX-like api, as well as other basic interfaces like argv, environment variables, random numbers, and timers.

https://wasi.dev

phickey··on Compiling C to WebAssembly Without Emscripten
Nice comprehensive writeup. The next step, beyond the basic allocator provided, would be to use wasi-sdk (https://github.com/cranestation/wasi-sdk) which provides a full musl-based libc, targeting the WASI interfaces. With this, you can invoke a C program with arguments, environment variables, and filesystem access.
phickey··on Lucet: Native WebAssembly Compiler and Runtime
Instantiation takes under 50 microseconds (us) on the lab machine I tested on, and 65us on my colleague's laptop. Loading the code takes about that long as well (see thread: https://twitter.com/acfoltzer/status/1111387279434485760). Compilation is not counted towards any of those tallies.

In our use case, we do compilation on a control plane system and distribute the shared object file to the fleet, so we aren't too concerned by it. For applications where compilation time is a bigger concern, I'm super impressed by this (still early) work on a one-pass wasm compiler: https://github.com/CraneStation/lightbeam

phickey··on Lucet: Native WebAssembly Compiler and Runtime
The lucet compiler and runtime each assume the other is implemented correctly, and its the job of some external system to make sure the runtime only loads code that came from the compiler. (We have infrastructure at Fastly that already does this for our edge cloud, and every use case will have different requirements).

The shared object code, when executed with lucet-runtime, should provide guarantees equivalent to those given by the wasm spec. However, we're not 100% to spec compliance yet, so there are some corners (e.g. import globals) that are not implemented. These dont cause a problem in practice, at the moment, because none of the toolchains we use to emit wasm use those features.

Loading code into the runtime is fast because its mostly a call to `dlopen`, followed by deserializing some metadata (with effort made to make this as efficient as possible). Instantiating modules is fast because it amortizes the syscall overhead by having pools of instances mostly-set-up ahead of time.

phickey··on Lucet: Native WebAssembly Compiler and Runtime
We started the codebase that became Lucet in July 2017. It went through a few fast iterations, and by Jan 2018 we had Cranelift running with AOT compilation. In the early days of Cranelift that meant adding support for position-independent code output and filling in a bunch of gaps in the x86_64 encodings and other really low level stuff. At the time, wasmtime (under the name wasm-standalone, i think?) was a lot less mature, and wasmer was not public yet. So, in a sense, we did (& continue to) contribute to both of those runtimes via Cranelift and other dependencies like Faerie.

We spent the bulk of 2018 solving performance and integration problems, rather than cleaning up the codebase to the point where we could open source it. In the meantime wasmer was released, and both wasmtime and wasmer made a ton of progress. Now that our stuff is open source, it is easier for us to collaborate with other runtimes, possibly by moving more code back into the common Cranelift parent, or by adopting modules from each other.

phickey··on Lucet: Native WebAssembly Compiler and Runtime
Like Steve says, performance is a complicated thing to measure. For one view on it, Lucet ships with a suite of microbenchmarks that compare its execution of wasm with the same C code compiled natively. The `make bench` target runs these. The most alarming regressions are in simple functions that take string arguments - the arguments have to be copied into the sandbox, and then the results copied out, in order to run a very simple function.

So, in those cases, we don't expect to match native, but things will get better when GC proposal lands in WASM, which gives support for operating on memory regions that are outside of WASM linear memory. But in most applications we've experimented with, we haven't found this overhead to be a showstopper.

phickey··on Lucet: Native WebAssembly Compiler and Runtime
That is a good summary! Lucet's runtime has a C API as well. We haven't created bindings to languages beyond C and Rust, but it should be pretty straightforward using the C API.
phickey··on Lucet: Native WebAssembly Compiler and Runtime
to answer the first question: It is 50us create a new instance from a loaded WebAssembly module. The module is compiled AOT into a shared object file, which is then loaded into the runtime using `dlopen`. We create instances from a region, which is basically a pool of memory that is already mostly setup, to minimize the computation & syscalls required in instance creation.
phickey··on Lucet: Native WebAssembly Compiler and Runtime
You need to checkout submodules - $ git submodule init && git submodule update. Sorry, multiple people have reported this problem, and we're adding it to the docs right now!
phickey··on Lucet: Native WebAssembly Compiler and Runtime
We hope so! Mozilla has been working on WASI support from Rust, and our team is working on supporting it from AssemblyScript as well: https://github.com/jedisct1/wasa.
phickey··on Lucet: Native WebAssembly Compiler and Runtime
We're not quite there yet, but we're working on answering those questions right now. Stay tuned!
phickey··on Lucet: Native WebAssembly Compiler and Runtime
I have not compared it to LuaJIT, but given that Lucet uses an AOT architecture, its hard to make a fair comparison.

There is no GUI story yet, but Lucet provides a WASI (https://wasi.dev) implementation, so as that standard evolves, we may be able to support GUIs through those interfaces.

phickey··on Lucet: Native WebAssembly Compiler and Runtime
We have a security document that addresses the big picture, and this specific concern as well: https://github.com/fastly/lucet/blob/master/SECURITY.md#cave... For speculative execution, we don't yet implement all of the mitigations possible in Lucet, but will in the near future.
phickey··on Lucet: Native WebAssembly Compiler and Runtime
At the moment, a lot of WASM tooling assumes instances interact with a JS engine. So, we aren't compatible with a bunch of existing tooling, like Rust's wasm-bindgen. We're working on our own tool to fill that hole in the ecosystem.

We also aren't 100% of the way to spec compliance yet. We have a plan to get there, but spent the last year or so putting the bulk of our effort into performance and integration with our edge cloud systems.

phickey··on Lucet: Native WebAssembly Compiler and Runtime
Author here- happy to take questions.
phickey··on Terrarium
Fastly labs engineer here - happy to answer any questions about this!
← PreviousPage 3 of 3