Skip to content

Conversation

@Robbepop
Copy link
Member

@Robbepop Robbepop commented Sep 10, 2025

Wasmi IR 3.0 definitions: #1650

Closed Issues

Closes #1598
Closes #1632
Closes #1639
Closes #1516
Closes #1485
Closes #1433
Closes #1324

Potential optimizations:

  • Use same ip in execution handlers as in op-decode. (🟢 -11% fibonacci/iter)
  • Integrate instance stack in CallStack into frames. (easy)
  • Return TrapCode::OutOfSystemMemory in Stack operations where necessary.
  • Redesign portable-dispatch to avoid state copy and improve performance. (medium)
  • Properly use extra-checks for technically-infallible conditional panics. (easy)
  • Use byte-offsets for Slot type to avoid mul-by-8 during execution. (easy)
  • Use extern "sysv64" ABI for execution handlers on Windows. (medium)
  • Use variable sized cell load/stores for 32-bit operands. (follow-up PR)
  • Make Wasmi IR Instance related instead of Module releated. (follow-up PR)

Development Notes

  • Interpretation loop must be panic-free for tail calls to be properly generated without the become keyword.
    • This means that we have to wrap host function calls with ::core::panic::catch_unwind and convert potential panics into flags signalling bad state to the interpreter.
    • Furthermore, we need to establish a way to signal to the interpretation loop that we are in an error state (e.g. encountered a bug) and have to exit the interpretation loop safely before resolving the bug, e.g. via panicking.

ToDo

Fix known bugs:

  • Fix bugs with branch operator execution.
    • Likely, the branch offsets are incorrect.
  • Fix integer-overflow in Wasmi translator.
  • Fix execution issue with recursive operation sequences.
  • Fix bug in stripping start and end of copy_span values in translator.
  • Fix bugs leading to incorrect reverse_complement result.
  • Fix bugs leading to incorrect regex_redux result.

Implement Functionality

  • Calling host functions from root.
  • Calling and resuming of resumable functions.
    • Calling functions resumably.
    • Resuming after out of fuel.
    • Resuming after host error.
  • Calling host functions from within Wasm functions.
    • call_imported
    • call_indirect
    • return_call_imported
    • return_call_indirect
  • Missing Wasmi IR execution handlers
    • br_table operators
    • return_call* operators
    • bulk memory operators
    • bulk table operators
    • simd operators
    • relaxed-simd operators
    • wide-arithmetic operators

Preliminary Benchmarks

Preliminary benchmarks of this WIP state pre-optimization shows interesting results:

execute/fibonacci/iter

Crate Features PR main %
578us 705us 🟢 -18%
compact 840us - 🔴 +19%
trampolines 1.92ms - 🔴 x2.7
compact+trampolines 1.8ms - 🔴 x2.6

execute/fibonacci/rec

Crate Features PR main %
2.84ms 3.77ms 🟢 -24%
compact 4.10ms - 🔴 +8%
trampolines 5.32ms - 🔴 +41%
compact+trampolines 6.3ms - 🔴 +67%

execute/fibonacci/tail

Crate Features PR main %
481us 777us 🟢 -38%
compact 728us - 🟢 -7%
trampolines 1.04ms - 🔴 +34%
compact+trampolines 1.26ms - 🔴 +62%

execute/tiny_keccak

Crate Features PR main %
114us 193ms 🟢 -41%
compact 183us - 🟢 -4%
trampolines 421ms - 🔴 x2.18
compact+trampolines 360ms - 🔴 x1.87

Benchmarks Conclusion

  • The tail-call-based direct-dispatch outperforms main significantly.
  • The tail-call-based indirect-dispatch is somewhat on par with main.
  • Both trampoline-based dispatches are wastly outperformed by main.
    • Note: the reason partly is really bad codegen due to unnecessary register copies which should be fixable.

@Robbepop Robbepop marked this pull request as draft September 10, 2025 08:21
@Robbepop Robbepop mentioned this pull request Sep 11, 2025
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 7 times, most recently from 41aad7c to bb8b966 Compare September 18, 2025 10:11
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 2 times, most recently from 12a19d4 to 64f420e Compare September 19, 2025 14:54
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 2 times, most recently from 48242ca to 4d2d316 Compare October 4, 2025 10:55
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch from 7bfb899 to c32c7c7 Compare October 24, 2025 13:52
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 4 times, most recently from d9ec934 to c68956c Compare November 2, 2025 23:40
Robbepop added a commit that referenced this pull request Nov 8, 2025
* improve debug_assert failure message

* fix field ordering of TableSet operations

* add #[inline(always)] to decode impl

Benchmarks show significant performance improvements.

* add #[inline(always)] to TryFrom<u16> for OpCode

* improve code formatting in match

* add trivial {Read,Write}As impls for UntypedVal

* add From<Memory> for u32 impl

* apply rustfmt
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 2 times, most recently from 12257b9 to 7a87159 Compare November 10, 2025 12:43
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 81.13208% with 400 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.81%. Comparing base (f0a1a46) to head (c4cf712).

Files with missing lines Patch % Lines
...ates/wasmi/src/engine/executor/handler/dispatch.rs 72.75% 191 Missing ⚠️
crates/wasmi/src/engine/translator/comparator.rs 43.20% 92 Missing ⚠️
crates/wasmi/src/engine/executor/handler/state.rs 87.71% 35 Missing ⚠️
crates/wasmi/src/engine/executor/handler/exec.rs 93.81% 30 Missing ⚠️
crates/wasmi/src/engine/executor/mod.rs 77.14% 16 Missing ⚠️
crates/wasmi/src/engine/executor/handler/eval.rs 81.25% 12 Missing ⚠️
crates/wasmi/src/engine/translator/func/encoder.rs 87.67% 9 Missing ⚠️
crates/wasmi/src/engine/translator/func/visit.rs 80.95% 4 Missing ⚠️
crates/wasmi/src/engine/executor/handler/utils.rs 98.03% 3 Missing ⚠️
...ates/wasmi/src/engine/translator/func/stack/mod.rs 0.00% 3 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1655      +/-   ##
==========================================
- Coverage   70.60%   62.81%   -7.80%     
==========================================
  Files         180      161      -19     
  Lines       15339    13698    -1641     
==========================================
- Hits        10830     8604    -2226     
- Misses       4509     5094     +585     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This now subsumes all non-resumable error reasons.
There even is a test for this to keep this exact behavior.
This roughly shrinks initial allocation size under default config by 8.
Those are more stable under debug conditions and also add more checks for improved debugging.
This is incorrect as demonstrated by the following example:
- `(1 & 2) == 0`
- `(1 != 0) && (2 != 0) == 1`
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch from d206f23 to ffbd7c8 Compare November 13, 2025 09:16
- compact -> indirect-dispatch
- trampolines -> portable-dispatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment