adambratschikaye opened issue #7652:
At DFINITY we've been looking into running the Wasmtime compilation of Wasm modules within Wasm itself (for sandboxing and determinism). It looks like we won't be able to use it at the moment because the performance hit is too large given that we lose the option to compile functions in parallel. But I have a rough POC with the changes needed to make this work and we were wondering if you'd be interested in merging them anyway, since it would be a pretty cool property of Wasmtime. There's still some cleanup needed and I'd be happy to help with that.
There's a more detailed description of the changes at the link provided, but most of it was just refactoring so that the functions
Config::build_compiler
andModule::build_artifacts
can be compiled towasm32
targets.
ulan commented on issue #7652:
@alexcrichton, @tschneidereit: ^ this is the result of exploring the idea you mentioned here: https://github.com/bytecodealliance/rfcs/pull/32#issuecomment-1740930345
alexcrichton commented on issue #7652:
Thanks for working forward on this, and it's great to see something already up and running!
I've skimmed over the changes you've made and they're all looking reasonable to me. I'd personally prefer though to have a different trajectory for integrating a change like this in the sense that I already feel like we have too many internal crates and I'd prefer to move towards consolidating them instead of proliferating them. In that sense I'd prefer to not add new
wasmtime-jit-runtime
orwasmtime-compile
crates but instead control this all through Cargo features of thewasmtime
crate if possible.Cargo features provides a good way in my mind to think about this and continue development of it into the future. It means that the Wasmtime CLI, for example, could be itself compiled to WebAssembly so long as everything except the
compile
command were disabled. The output ofcompile
would be usable by Wasmtime of the same version though. Reducing the number of crates additionally helps keep things a bit more maintainable internally I think since there's less of a question of what-goes-where.Organizationally what I'd recommend is to move all target-agnostic things, such as
wasmtime_jit::ObjectBuilder
, intowasmtime-environ
. Thewasmtime-environ
crate already actually compiles to WebAssembly and is used by jco. In that sense thewasmtime-environ
crate is a suitable location for "stuff things here that compile everywhere and have no system dependencies". I think that thewasmtime-compile
andwasmtime-jit-runtime
crates could probably be merged intowasmtime-environ
. One day I'd like to merge the{wasmtime-runtime, wasmtime-jit, wasmtime}
crates if possible since I don't think we're getting much mileage from the distinction right now.
I've also been wondering a bit about the threading issue you mention since I think that's important to solve. One initial way I was thinking it might be solved was explicit threading on the host, for example no shared state and a
Store
-per-thread where the embedder orchestrates the threads and calls cranelift once-per-function. Wiring this all up I don't think is that feasible though since it would be exposing a lot of internals of Wasmtime which wouldn't be great.Alternatively though one option would be the
wasm32-wasi-threads
target. While I haven't tested it myself I think that therayon
crate should work there so in theorywasmtime run -S threads wasmtime.wasm compile ...
should "just work" and have internal parallelism. That would then also work from an embedder point of view assuming you wouldn't use the literal CLI itself.
bjorn3 commented on issue #7652:
wasm32-wasi-threads doesn't work with the wasi-preview2 based wasi-preview1 implementation in wasmtime, right?
alexcrichton commented on issue #7652:
Correct, yeah, that's tracked by https://github.com/bytecodealliance/wasmtime/issues/7551.
adambratschikaye commented on issue #7652:
Regarding merging the crates and using features, what would you think about the following steps?:
- Move everything target agnostic from
wasmtime-jit
towasmtime-environ
.- Move the remaining parts of
wasmtime-jit
intowasmtime
and removewasmtime-jit
.- Put everything target specific in
wasmtime
under a feature, such that we can compile it towasm32
if that feature isn't enabled.I'm not sure how messy step 3 would end up being. Maybe it would be easier to move the parts of
wasmtime
required for compilation fromwasmtime
towasmtime-environ
instead of 3?
alexcrichton commented on issue #7652:
Step 1/2 sound good to me.
For step 3 I agree things may get a bit messy. One possibility though is we could have:
crates/wasmtime/src/runtime/*.rs
- all runtime bits, only one cfg to turn off the entire thingscrates/wasmtime/src/compile/*.rs
- all compiling bits, only one cfg to turn off as wellThe final crate structure of types like
wasmtime::Instance
would be the same but everything would be defined undercrates/wasmtime/src/runtime/store.rs
for example. I'd personally prefer to slurp things into thewasmtime
crate rather than the other way around, but not at the cost of large contortions so if you find it's too difficult to go that direction I think it's reasonable to move agnostic things intowasmtime-environ
.
adambratschikaye commented on issue #7652:
Sounds good, I'll give it a try.
adambratschikaye closed issue #7652:
At DFINITY we've been looking into running the Wasmtime compilation of Wasm modules within Wasm itself (for sandboxing and determinism). It looks like we won't be able to use it at the moment because the performance hit is too large given that we lose the option to compile functions in parallel. But I have a rough POC with the changes needed to make this work and we were wondering if you'd be interested in merging them anyway, since it would be a pretty cool property of Wasmtime. There's still some cleanup needed and I'd be happy to help with that.
There's a more detailed description of the changes at the link provided, but most of it was just refactoring so that the functions
Config::build_compiler
andModule::build_artifacts
can be compiled towasm32
targets.
adambratschikaye commented on issue #7652:
I think we can close this as https://github.com/bytecodealliance/wasmtime/pull/7766 is merged.
Last updated: Nov 22 2024 at 17:03 UTC