Switch interpreter dispatch to musttail (become) threading#382
Open
kvpanch wants to merge 7 commits into
Open
Conversation
Replace the central loop in `InterpretedInstance::run_impl` with direct-threaded dispatch: each handler now ends in `become dispatch(self, next_off)` and `dispatch` (inlined) tail-jumps to the next handler. This collapses the per-instruction call/ret pair into a single indirect tail jump, and moves the indirect-branch site from one shared loop to the tail of every handler so the BTB learns per-edge transition patterns. Requires nightly + `#![feature(explicit_tail_calls)]`. The recompiler is untouched. Measured deltas on bench-pinky / bench-prime-sieve / bench-memset / bench-minimal (host: x86_64, best-of-N runs): | Benchmark | Baseline | Patched | Delta | |------------------------------|------------|------------|---------| | runtime/memset/32 | 43.66 ms | 37.99 ms | -13.0% | | runtime/memset/64 | 45.02 ms | 37.40 ms | -16.9% | | runtime/minimal/64 | 15.60 us | 12.07 us | -22.6% | | runtime/pinky/32 | 128.05 ms | 97.69 ms | -23.7% | | runtime/pinky/64 | 122.43 ms | 91.45 ms | -25.3% | | runtime/prime-sieve/32 | 96.20 ms | 60.76 ms | -36.8% | | runtime/prime-sieve/64 | 75.67 ms | 49.90 ms | -34.1% | | interpreter runtime mean | | | -20.3% | | compiler runtime mean (ctrl) | | | -0.6% |
Contributor
Author
|
@koute gentle ping |
koute
reviewed
May 12, 2026
Comment on lines
+7
to
+9
| if [ "$(cat /proc/sys/vm/unprivileged_userfaultfd)" != "1" ]; then | ||
| echo "1" | sudo tee /proc/sys/vm/unprivileged_userfaultfd > /dev/null | ||
| fi |
Collaborator
There was a problem hiding this comment.
This shouldn't be here (and it's not needed for interpreter-only tests.)
Contributor
Author
There was a problem hiding this comment.
Tests that are executed will fail otherwise https://github.com/paritytech/polkavm/actions/runs/25462114909/job/74706643514
Collaborator
There was a problem hiding this comment.
Yes, because those are recompiler tests.
Contributor
Author
There was a problem hiding this comment.
I see your comment down below to drop some tests. I should be able to remove this line
Contributor
Author
|
@koute gentle ping |
koute
reviewed
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the central loop in
InterpretedInstance::run_implwith direct-threaded dispatch: each handler now ends inbecome dispatch(self, next_off)anddispatch(inlined) tail-jumps to the next handler. This collapses the per-instruction call/ret pair into a single indirect tail jump, and moves the indirect-branch site from one shared loop to the tail of every handler so the BTB learns per-edge transition patterns.Requires nightly +
#![feature(explicit_tail_calls)]. The recompiler is untouched.Measured deltas on bench-pinky / bench-prime-sieve / bench-memset / bench-minimal (host: x86_64, best-of-N runs):