alexcrichton opened PR #14683 from alexcrichton:optimize-ref-func to bytecodealliance:main:
This PR is a series of commits which ends up optimizing the
ref.funcimplementation within Wasmtime to notably not require a hostcall and additionally not require any function lookups within the compiled function tables. There's a number of linked issues to poor performance ofref.funcand while this isn't a truly "zero cost" implementation it is significantly faster than it otherwise is today. The same implementation as before, where the fields are unconditionally initialized, is used no matter what. Conditional initialization could be part of a later runtime refactoring, if needed.Note: this is a draft PR since there's an open design question around the Cranelift side of things I'd like to discuss this coming Wednesday.
alexcrichton updated PR #14683.
github-actions[bot] added the label cranelift on PR #14683.
github-actions[bot] added the label cranelift:area:aarch64 on PR #14683.
github-actions[bot] added the label wasmtime:api on PR #14683.
alexcrichton updated PR #14683.
alexcrichton updated PR #14683.
alexcrichton has marked PR #14683 as ready for review.
alexcrichton requested cfallin for a review on PR #14683.
alexcrichton removed the review request for wasmtime-compiler-reviewers from PR #14683.
alexcrichton requested wasmtime-compiler-reviewers for a review on PR #14683.
alexcrichton requested wasmtime-core-reviewers for a review on PR #14683.
alexcrichton edited PR #14683:
This PR is a series of commits which ends up optimizing the
ref.funcimplementation within Wasmtime to notably not require a hostcall and additionally not require any function lookups within the compiled function tables. There's a number of linked issues to poor performance ofref.funcand while this isn't a truly "zero cost" implementation it is significantly faster than it otherwise is today. The same implementation as before, where the fields are unconditionally initialized, is used no matter what. Conditional initialization could be part of a later runtime refactoring, if needed.
Note: this is a draft PR since there's an open design question around the Cranelift side of things I'd like to discuss this coming Wednesday.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
I've a thread on Zulip about why this isn't optimizing
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
I don't think this is something that can be inferred, because that would require determining whether a given function call writes to the location (or alias region) in question.
I think we may want to, in the limit of time, annotate signatures with the set of alias regions they use (and maybe, in the fullness of time, split that into observe vs mutate), but that is a bit separate from this TODO I think.
:speech_balloon: fitzgen created PR review comment:
"the this"
:speech_balloon: fitzgen created PR review comment:
This is going to lose whether the field is aligned or not, for example. I think this should instead be something like
let flags = self.flags_with_region(cursor.func).with_readonly(false);
:speech_balloon: fitzgen created PR review comment:
Can the new relocations be added in a separate PR, just to help split this up and make it easier to review?
:speech_balloon: fitzgen created PR review comment:
doc comment needs fixing
:speech_balloon: alexcrichton created PR review comment:
Unfortunately the core change here can't land without this since otherwise tests on aarch64/riscv64 will fail. I can land the change for relocations separately, but then they're not tested until this lands. I split them out into separate commits for this PR, but if you'd like I can land them ahead of time on
main
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Do you think it's worth having this comment at all? I tried to capture some of the Cranelift meeting discussion in this, but you're right that actually removing the need for this would be a pretty ambitious project
:memo: alexcrichton submitted PR review.
alexcrichton updated PR #14683.
alexcrichton updated PR #14683.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Sorry for the delayed response. Yeah I think we can remove this comment now, especially given the other changes that have landed or are in-progress clarifying
readonlyand adding GVN ofreadonlyloads.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
I think landing them without tests in a separate PR first would have been easier to review (since Github makes it hard to mark files read while reviewing commit by commit) but I think it is fine at this point.
:thumbs_up: fitzgen submitted PR review:
Thanks!
alexcrichton updated PR #14683.
alexcrichton has enabled auto merge for PR #14683.
alexcrichton added PR #14683 Optimize the implementation of ref.func to the merge queue
:check: alexcrichton merged PR #14683.
alexcrichton removed PR #14683 Optimize the implementation of ref.func from the merge queue
Last updated: Oct 31 2026 at 23:03 UTC