fitzgen opened PR #11148 from fitzgen:no-clone-drop-arc-in-vmmemory-method to bytecodealliance:main:
Getting the base pointer from the underlying
dyn RuntimeLinearMemoryinvolved getting aMemoryBasewhich is potentially anMmapOffsetwhich itself contains anArc<Mmap>, and we would then callbase.as_non_null()to turn this into a raw pointer, and then we would drop theMemoryBasewhich ultimately drops theArc<Mmap>. So that's anArcclone and drop just to get aVMMemoryDefinition, which is just a pointer and a length, essentially a slice of the linear memory. And, among other places, we callLocalMemory::vmmemoryto get the GC heap's memory base and bound every time we access a GC object from Rust (for example, during collections).Altogether, this removes another 30% of runtime from the testcase in https://github.com/bytecodealliance/wasmtime/issues/11141
<!--
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 ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
fitzgen requested dicej for a review on PR #11148.
fitzgen requested wasmtime-core-reviewers for a review on PR #11148.
fitzgen commented on PR #11148:
All that said, I don't love how this PR introduces a second version of the "same" method. It might be nicer to instead add a
vmmemorymethod toRuntimeLinearMemoryand pushVMMemoryDefinitionconstruction down to implementations of that trait, rather than tying together the results of differentRuntimeLinearMemorymethods inLocalMemory.That would actually let us avoid an indirect call too:
- Now:
LocalMemoryindirect-calls thebyte_sizemethod through adyn RuntimeLinearMemoryLocalMemoryindirect-calls thebase(nowbase_non_nullin this PR) method through adyn RuntimeLinearMemoryLocalMemoryputs them together into aVMMemoryDefinition- Alternative:
LocalMemoryindirect-calls the hypotheticalvmmemorymethod through adyn RuntimeLinearMemory- The
RuntimeLinearMemoryimplementation gets its byte size and base, which can both be done directly/inlined/etc because we aren't crossing adynboundary anymore- The
RuntimeLinearMemoryimplementation puts them together into aVMMemoryDefinition- The
VMMemoryDefinitionis returned to theLocalMemory, which returns it to its caller in turnNote that the "now" sequence has two indirect calls while the alternative has only one.
I'm going to whip this alternative up real quick and then update this PR.
fitzgen updated PR #11148.
fitzgen commented on PR #11148:
I'm going to whip this alternative up real quick and then update this PR.
I've pushed a commit that implements this.
alexcrichton submitted PR review.
alexcrichton merged PR #11148.
Last updated: Dec 06 2025 at 06:05 UTC