# Interpreter dispatch and performance on WebAssembly

**URL:** <https://discuss.python.org/t/interpreter-dispatch-and-performance-on-webassembly/27246>\
**Category:** WebAssembly\
**Created:** [May 30, 2023, 10:47pm UTC](https://discuss.python.org/t/interpreter-dispatch-and-performance-on-webassembly/27246 "2023-05-30T22:47:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoodmane](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hoodmane/32/4037_2.png) [@hoodmane](https://discuss.python.org/u/hoodmane)\
**Post date:** [May 30, 2023, 10:47pm UTC](https://discuss.python.org/t/interpreter-dispatch-and-performance-on-webassembly/27246/1 "2023-05-30T22:47:20Z")

</div>

@markshannon suggested at pycon that we might use tail calls for interpreter dispatch to improve interpreter performance in webassembly. I did some experiments based on [Eli Bendersky’s 2012 blog post](https://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables) and found around a 12% performance benefit.

> **[GitHub - hoodmane/dispatch-performance-experiment](https://github.com/hoodmane/dispatch-performance-experiment)**
>
> Contribute to hoodmane/dispatch-performance-experiment development by creating an account on GitHub.

With native clang, tail calls have a 10% performance benefit over switch whereas in Emscripten they have a 12% performance benefit.

In gcc, I reproduce the same 20% performance benefit that Eli Bendersky quotes for computed goto over switch. Interestingly, switch-based dispatch is faster in clang than in gcc and computed goto is slower so computed goto has a much smaller 10% benefit over switch in clang. With gcc, tail calls are 8% slower than computed goto whereas with clang tail calls are 1% faster than computed goto.
