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. (🟢 -5%)
  • Return TrapCode::OutOfSystemMemory in Stack operations where necessary.
  • Redesign portable-dispatch to avoid state copy and improve performance. (🟢 -10-30%)
  • Use loop+match for portable indirect dispatch. (🟢 -10-20%)
  • 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: Implement variable sized VM registers #1671
  • Make Wasmi IR Instance related instead of Module related: Move Wasm function details into the Store #1492

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%
indirect 840us - 🟠 +19%
portable 1.38ms - 🔴 +96%
indirect+portable 823us - 🟠 +16%

execute/fibonacci/rec

Crate Features PR main %
2.84ms 3.77ms 🟢 -24%
indirect 4.10ms - 🟠 +8%
portable 4.58ms - 🔴 +22%
indirect+portable 4.64ms - 🔴 +23%

execute/fibonacci/tail

Crate Features PR main %
481us 777us 🟢 -38%
indirect 728us - 🟢 -7%
portable 1.08ms - 🔴 +39%
indirect+portable 883us - 🟠 +13%

execute/tiny_keccak

Crate Features PR main %
114us 193ms 🟢 -41%
indirect 183us - 🟢 -4%
portable 327ms - 🔴 +69%
indirect+portable 258ms - 🔴 +33%

Benchmarks Conclusion

  • The tail-call-based direct-dispatch outperforms main significantly.
  • The tail-call-based indirect-dispatch is somewhat on par with main.
  • Both portable dispatch techniques are significantly outperformed by main.
    • Note: the reason partly is kinda bad codegen in the hot-path. Further investigation needed.

@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 85.31469% with 189 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.70%. Comparing base (376e3a8) to head (c9c607a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/wasmi/src/engine/executor/handler/func.rs 73.04% 31 Missing ⚠️
...c/engine/executor/handler/dispatch/backend/loop.rs 43.75% 27 Missing ⚠️
crates/wasmi/src/engine/executor/handler/state.rs 88.84% 27 Missing ⚠️
crates/wasmi/src/engine/executor/handler/exec.rs 92.81% 25 Missing ⚠️
...tes/wasmi/src/engine/executor/handler/exec/simd.rs 71.08% 24 Missing ⚠️
crates/wasmi/src/engine/executor/mod.rs 77.14% 16 Missing ⚠️
.../wasmi/src/engine/executor/handler/dispatch/mod.rs 82.35% 9 Missing ⚠️
...c/engine/executor/handler/dispatch/backend/tail.rs 0.00% 6 Missing ⚠️
crates/wasmi/src/engine/translator/func/encoder.rs 44.44% 5 Missing ⚠️
crates/wasmi/src/engine/translator/comparator.rs 77.77% 4 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1655      +/-   ##
==========================================
- Coverage   70.66%   69.70%   -0.97%     
==========================================
  Files         180      166      -14     
  Lines       15338    13340    -1998     
==========================================
- Hits        10839     9298    -1541     
+ Misses       4499     4042     -457     

☔ 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.

@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch from 8f5a07a to 5e0035d Compare November 25, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment