Comments (8)
I got this working with a crude encoding scheme. Each isa::Instruction
is identified with a single u8
, followed by any operands (usually u32
). As of now, I'm seeing a 10-15% performance improvement in cargo bench
results.
The savings aren't as large as I had hoped. A napkin-math analysis over the test suite gives me a thought:
Most of the u32
operands are slots or offsets or similar small integers. Maybe a variable length encoding scheme is worth a go?
from wasmi.
10-15% is a very good figure actually!
This is basically a trade-off and we can easily get more overhead than we save by compacting the bytecode. What we might want to explore is introduction of a special narrow versions of opcodes that takes, say, u16 instead of u32 immediates.
from wasmi.
Well… then I started thinking about how WebAssembly is already a compact bytecode format with variable-length encoding of operands. FunctionReader::read_instruction()
swizzles around flow control, but many more instructions are validated then emitted 1:1. Maybe it's better not to produce a second bytecode, but to instead produce a mix of new/enriched flow control instructions along with references to the original bytecode.
from wasmi.
Maybe it's better not to produce a second bytecode, but to instead produce a mix of new/enriched flow control instructions along with references to the original bytecode.
Can you expand a little on this? I'm not sure I follow.
from wasmi.
This issue proposes decoding instructions for validation, re-encoding them to a new bytecode, and decoding that bytecode in the interpreter.
I'm now thinking about decoding instructions for validation, building &[u8]
s of which instructions do not require special handling, and then decoding those instructions from the original bytecode again in the interpreter. Something like:
mod isa {
pub enum Operation { // formerly Instruction
GetLocal(u32),
SetLocal(u32),
TeeLocal(u32),
Br(Target),
BrIfEqz(Target),
BrIfNez(Target),
BrTable(Box<[Target]>),
Return(DropKeep),
/// WebAssembly bytecode, guaranteed not to contain:
///
/// * `Nop`
/// * `Block`
/// * `Loop`
/// * `If`, `Else`, `End`
/// * `Br`, `BrIf`, `BrTable`
/// * `Return`
/// * `GetLocal`, `SetLocal`, `TeeLocal`
///
/// All other instructions are permissible and have valid operands.
ValidatedWasmBytecode(&[u8]),
}
}
The existing bytecode format is equivalent for most instructions, and wasmi
already knows how to decode it. It's denser than my u32
immediate format and thus ought to make better use of memory bandwidth. I intend to experiment in this direction :-)
from wasmi.
Related:
- paritytech/parity-wasm#135
- paritytech/parity-wasm#154
- https://github.com/yurydelendik/wasmparser.rs/pull/45
from wasmi.
I am going to implement a more compact encoding of wasmi
bytecode for the v1
implementation introduced in #287.
from wasmi.
The mentioned PR (#287) shrank the size of the enum
bytecode from 24 bytes to 16 bytes by disentangling BrTable
variant. The BrCode
operand now only hosts the number of targets excluding the default target and is followed by Branch
and Return
operands by construction of the wasmi
bytecode.
Closing this issue now since we probably won't get way lower than that given that we embed constant values into the bytecode since indirectly accessing constants (that must be 64-bits) would create too much overhead.
from wasmi.
Related Issues (20)
- Differential Fuzzing: compare linear memories and global variables between backends after each execution HOT 1
- Support for Alternative Memory Backing Options HOT 13
- Allow Wasmi optimizer to look behind function local constant registers HOT 2
- Run CI tests using LLVM's address sanitizer
- Harden fuzzing with respect to non-deterministic behaviors between Wasm engines
- Add Wasmer (Singlepass) and Wasmer (Cranelift) to differential fuzzing infrastructure
- Clean-up differential fuzzing infrastructure
- Implement the Wasm `component-model` proposal HOT 2
- CI: Run Wasm spec testsuite with `miri`
- Big performance regression between 0.31 and 0.32 HOT 7
- Optimization: Special handling for common shadow stack instruction sequences HOT 1
- Create C bindings for Wasmi
- Simplification: Rewrite `iNN.sub` with immediate to new `iNN.add` variant
- Restore CI benchmarks HOT 1
- Wasmi versions `0.32.0-beta.6` cannot run `ffmpeg.wasm` correctly HOT 20
- Update `wasmi_wasi` WASI implementing dependencies HOT 1
- Optimization: Fuse transitive copies HOT 1
- Add `--verbose` mode to Wasmi CLI HOT 2
- Add support for fully hibernate-able Wasm instances HOT 7
- Handle host function calls the same as other instructions in the Wasmi executor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasmi.