paritytech / smoldot

Alternative client for Substrate-based chains.
GNU General Public License v3.0
309 stars 74 forks source link

Replace wasmtime with lucet #4

Closed tomaka closed 4 years ago

tomaka commented 4 years ago

As recommended by @pepyakin

https://docs.rs/lucet-runtime

expenses commented 4 years ago

@pepyakin Is there a good explanation somewhere of what the difference between the two is?

pepyakin commented 4 years ago

Not sure if there is, but here is tl;dr:

lucet was started by Fastly for their edge computation thingy (and wasmtime was started by Mozilla). Because of that this engine has some quite specific features.

For one, lucet has a strong inclination towards ahead-of-time execution, so much, that the pipeline is divided on two parts: 1. compile wasm code and get a friggin *.so and 2. when execution needed they would load this *.so quickly and execute it. I mean it, looks like it's designed with out-of-process compiler in mind. They in general try to optimize for super fast startup time.

Another feature (in fact it's why lucet surfaced in our discussion in the first place) is that they support stack switching. That would allow lucet to better fit into the execution model of substrate-lite: instead of blocking host functions they could be implemented in async fashion with lucet.

Alas, in the same discussion, we uncovered that it would be a bit of a pain to use lucet because, (after glancing at the public api), it requires declaring all the host functions upfront. And unfortunately, substrate-lite, akin substrate, is structured with a variable host function list, so that would require a bit of refactoring.

To get more info about lucet you can look at their docs

pepyakin commented 4 years ago

A relevant issue for wasmtime https://github.com/bytecodealliance/wasmtime/issues/1007

tomaka commented 4 years ago

I'd go with keeping wasmtime, and when https://github.com/bytecodealliance/wasmtime/issues/1007 is done we can get rid of the weird task-switching code. I'm really not a fan of lucet's approach.

tomaka commented 4 years ago

For reference, in #55 I went with my own library (https://github.com/tomaka/corooteen) because:

pepyakin commented 4 years ago

Good job!

I guess this can be closed now