cfallin opened PR #15381 from cfallin:fix-invalidate-hook-perf to bytecodealliance:main:
On some libcalls (e.g.
memory.copy/memory.fill), which are very hot, the Wasm-to-host transition invoking invalidation logic can be observably quite expensive (5-10% benchmark hits).We introduced a GC-epoch bump for unrooted refs recently in #15191, and then refactored/generalized the epoch-bump to handle the "execution version" scheme used by
FrameHandles in #15358 as well. Starting with the former and continuing with the latter, we required a vtable-indirect method invocation on the&mut dyn VMStoreto do this epoch-bump from withincatch_unwind_and_record_trap.This PR introduces a small "effect scheme" framework for libcalls. The idea is that if we know a libcall is either (i) completely pure, or (ii) only mutates state on its own in a way that is (ii-a) tracked (e.g. for watchpoints) separately, and (ii-b) still a leaf function, then we don't need to invalidate handles. It's as-if the Wasm code had inlined all the implementation of the libcall -- we just happen to place it in the runtime instead.
So we pass a
LibCallEffecttocatch_unwind_and_record_trapnow, and gate theon_wasm_to_host_transitionindirect call on it. Together with an inlining annotation, we const-fold this check in each libcall entry point so in practice we don't have any code at all in the fast libcalls like memcpy/memmove (and recover the tail-call to memcpy/memmove that we had before).This eliminates all perf regression seen from just-before-#15191 to present. Thus, it fixes #15342.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
cfallin removed the review request for wasmtime-core-reviewers from PR #15381.
cfallin requested dicej for a review on PR #15381.
cfallin requested wasmtime-core-reviewers for a review on PR #15381.
Last updated: Nov 19 2026 at 20:05 UTC