How TinyWasm's internal bytecode and execution works
nextTinyWasm does not interpret WebAssembly instructions directly. Instead, it follows a multi-stage process to optimize execution:
- Parsing & Validation: WebAssembly is translated into a compact internal bytecode format.
- Lowering: Structured control flow (like
block,loop,if,br*) is resolved ahead of time into jump-oriented instructions such asJump,JumpIfZero,BranchTable*,DropKeep*, andReturn. - Optimization: A peephole optimizer (
optimize.rs) performs superinstruction fusion. It combines common sequences (like binary operations with local access or comparisons with conditional branches) into single instructions to reduce interpreter dispatch overhead. - Execution: The runtime uses a single iterative interpreter loop over the lowered, optimized instruction stream.
This architecture allows modules to be optionally serialized as .twasm files for faster reuse, as the heavy lifting of parsing and lowering is already complete.