-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Mirror Wasmtime API in wasmi #287
Conversation
Codecov Report
@@ Coverage Diff @@
## master #287 +/- ##
==========================================
- Coverage 79.56% 79.48% -0.09%
==========================================
Files 31 69 +38
Lines 4738 9118 +4380
==========================================
+ Hits 3770 7247 +3477
- Misses 968 1871 +903
Continue to review full report at Codecov.
|
This allows the wasmi v2 interpreter to eliminate an indirection when calling a Wasm function.
For visit to work properly for BrTable targets we need access to the underlying slice of instructions.
This will later include the entire interpreter implementation specific to each wasmi bytecode instruction.
These two fields are not necessary but act as optimizations in the common case of accessing the default linear memory or default table of the associated module instance.
The local variables are now stored directly in the bytecode. This reduces the number of indirections required upon calling.
Running the start function has not yet been implemented.
# Conflicts: # benches/src/lib.rs
This yielded some inconsistencies with wasmi's trap handling so far.
# Conflicts: # tests/spec/mod.rs
This heavily improves performance of v1 but does not much to v0.
We clarified internally that this PR is too big to be reviewed properly so we concentrate QA on follow-up PRs for extra fuzzing, and polishing. |
This PR builds a new API for
wasmi
inspired by Wasmtime: https://docs.rs/wasmtime/0.32.0/wasmtime/Preliminary Benchmarks
The above benchmarks show that the general overhead of
v1
is greatly reduced compared tov0
and for long running tasks for engines seem to operate with a comparable performance. Note though thatv1
has not yet been optimized.Benchmark profile ran with
lto = "fat"
andcodegen-units = 1
, otherwise performance is going to be worse forv1
.Expected Results
RefCell
andRc
that are counter intuitive for Rust.multivalue
Wasm proposal. (partial)wasmi
and Wasmtime.Follow-up PRs
v1::Module
tov1::Engine
. #305wasmparser
crate for v1 Wasm parsing and validation #307Usage
The typical usage of the new API is very similar to the usage of the Wasmtime API. In summary:
Engine
type. This is the newwasmi
interpreter. We call itEngine
instead ofInterpreter
since it also hosts all the Wasm function bodies as the WasmtimeEngine
does. This has two main reasons.Affected Issues
Send
andSync
since most of them are just type safe references.v1
engine still useswasmi-validate
crate with its unstructured errors, however, the unstructured errors of theprepare
module are gone.CodeMap
abstraction helps to reduce pointer chasing and stores all function bodies in a single allocation.FuncBody
reference type directly points into theCodeMap
where its instructions can be found. So from aFuncBody
there is exactly one indirection happening to resolve function instructions. Also local variable information now resides directly next to the instructions and therefore also no longer requires yet another pointer chasing.v1
uses structured error types and makes no use ofString
types internally.InstructionBuilder
andVisitInstruction
abstractions greatly help in experimenting with newwasmi
bytecode designs since decouple data from operations.What the WIP won't do
wasm-tools
such aswasmparser
, yet.runner.rs
,compile.rs
as possible but tries to make it simpler for follow-ups to make changes to those parts of the code.ToDo List
Caller
with respect to its internalInstance
handle.v1
interpreter.v1
engine:wasm_f32
wasm_f32_bitwise
wasm_f64
wasm_f64_bitwise
float_misc
wasm_imports
wasm_linking
Since version 1.1 WebAssembly no longer demands this behavior and the currentwasm_linking
test fails because instantiation of a module where the failure happens after element section and data sections are processed may leave the respective manipulated tables or linear memories in an invalid state. The fix is that instantiation should happen as if it was a transaction with this regard.v1
implementation seems to be fine. The only issue is that our currently embraced Wasm spec testsuite is quite outdated. Updating is not easy since many unimplemented Wasm proposals (such asmultivalue
) are included by default in later revisions.wasm_skip_stack_guard_page
wasm_skip_guard_page
test fails because the value stack currently is missing adjustment with respect to function stack height requirements. This is planned to be implemented soon anyways. When artificially increasing the default value stack height, the test starts to succeed.wasm_start
v1
interpreter.wast
instead ofwabt
for parsing of.wast
files.Instance::exports
method and makeInstance::get_export
public.wasmtime::Linker::instance
LittleEndianConvert
trait into its own PR forwasmi
.Func::instance
andFunc::func_body
and useFunc::as_internal
instead.Func::as_internal
is more efficient and covers more use cases.start
function has not yet been executed.Linker::instantiate
for better user experience with respect to imports resolution.InstancePre
to properly control execution of thestart
function.wasmi
interpreter.FunctionFrame
.wasmi
bytecode.parity_wasm
Module
andwasmi-validator
as well as most of the existing compilation process.wasmi
bytecode is generated instead of the old one and that code is fed into the newwasmi
Engine
instead of being collected inside thewasmi
Module
.wasmi
codegen.Rendered Docs (WIP)
Rendered docs of what has been implemented so far (2021-12-27):