Tail-Call Interpreters in Rust: A Benchmark of VM Dispatch Techniques
Tail-Call Interpreters in Rust – Jimmy Ostler
Jimmy Ostler explores tail-call interpretation in Rust by implementing several VM dispatch styles inspired by Noel Welsh's Scala post. He covers switch, subroutine, indirect, and direct dispatch, using Rust's unstable `become` keyword for guaranteed tail-call optimization. Benchmarking on a simple stack machine, he finds direct dispatch—where each operation calls the next—performs best on his machine, offering insights for optimizing interpreter performance.
This leads to direct dispatch. We return to objects as bytecode (for now) and let each operation dispatch the next. This results in what turns out to be the best performing variation on my machine.
- sph
Ctrl-Shift-C, click on a paragraph, search for "text-shadow" on the right pane of the inspector, untick the checkbox.
There is a time and place for text and retro-CRT effects, this isn't one.
- noelwelsh
Made my day that it references an article I wrote! :-D
Another thing that is kinda neat: there is a duality (a bidirectional transform) between the AST for a tree walking interpreter and the AST for a stack machine. To create the stack machine AST, all you do is remove any occurrence of the expression type in the tree-walking AST; these values are now found on the stack. Obvious when you think about it, but useful nonetheless. I don't think there is a simple equivalent for a register machine as, unless you have an infinite number of registers, you need to do register allocation.
(If the author reads this, my name changed from Noel to Neal at some point. I don't really mind though; my name is a bit unusual and I've been called all sorts of things.)
- rootnod3
That is a whole lot of unsafe blocks.
- froh42
Why the fuck make a tech web page unreadable with CRT effects? Thank god, there is reader mode in Firefox.