alexcrichton opened issue #4191:
Currently whenever an instance is created Wasmtime will calculate the
VMOffsetsstructure (also for the pooling allocator). ThisVMOffsetsstructure which is actually quite large is also stored within theInstanceallocation for each instance. This means that every instantiation is redoing this work and additionally "wasting" space by storing this in eachInstance. While the cost of computation here and the cost of initializing this storage is pretty small I think this would still be good to fix.I think a better solution would be to perhaps store the
VMOffsetsin theruntime_infofield since this information is statically known when the module is created and it can live in one location in the module and be referenced indirectly by each instance. The reason I hesitate to do this though is that accessing the vmoffsets would then become a dynamic function call (sinceModuleRuntimeInfois a trait). as opposed to today where information is at a static offset withinInstance. I'm worried about the runtime impact of naively moving this information behindModuleRuntimeInfo(sinceVMOffsetsis pretty hot).I'm not sure how best to solve this immediately, but some possibilities include:
- We could store a raw pointer, returned by
ModuleRuntimeInfo, intoInstanceso we call the indirect function once at construction and then never again.- The
ModuleRuntimeInfocould perhaps return anArc"package" of various other bits and pieces of information that don't need to go through a virtual lookup. Or otherwise we could do away with theModuleRuntimeInfotrait and instead have some sort of structure there which is precomputed for eachModule(this would be a large-ish refactoring).And possibly other strategies as well. Given the relatively low impact of having this stored in each instance though this isn't the most pressing issue.
alexcrichton labeled issue #4191:
Currently whenever an instance is created Wasmtime will calculate the
VMOffsetsstructure (also for the pooling allocator). ThisVMOffsetsstructure which is actually quite large is also stored within theInstanceallocation for each instance. This means that every instantiation is redoing this work and additionally "wasting" space by storing this in eachInstance. While the cost of computation here and the cost of initializing this storage is pretty small I think this would still be good to fix.I think a better solution would be to perhaps store the
VMOffsetsin theruntime_infofield since this information is statically known when the module is created and it can live in one location in the module and be referenced indirectly by each instance. The reason I hesitate to do this though is that accessing the vmoffsets would then become a dynamic function call (sinceModuleRuntimeInfois a trait). as opposed to today where information is at a static offset withinInstance. I'm worried about the runtime impact of naively moving this information behindModuleRuntimeInfo(sinceVMOffsetsis pretty hot).I'm not sure how best to solve this immediately, but some possibilities include:
- We could store a raw pointer, returned by
ModuleRuntimeInfo, intoInstanceso we call the indirect function once at construction and then never again.- The
ModuleRuntimeInfocould perhaps return anArc"package" of various other bits and pieces of information that don't need to go through a virtual lookup. Or otherwise we could do away with theModuleRuntimeInfotrait and instead have some sort of structure there which is precomputed for eachModule(this would be a large-ish refactoring).And possibly other strategies as well. Given the relatively low impact of having this stored in each instance though this isn't the most pressing issue.
alexcrichton commented on issue #4191:
Done in https://github.com/bytecodealliance/wasmtime/pull/5346
alexcrichton closed issue #4191:
Currently whenever an instance is created Wasmtime will calculate the
VMOffsetsstructure (also for the pooling allocator). ThisVMOffsetsstructure which is actually quite large is also stored within theInstanceallocation for each instance. This means that every instantiation is redoing this work and additionally "wasting" space by storing this in eachInstance. While the cost of computation here and the cost of initializing this storage is pretty small I think this would still be good to fix.I think a better solution would be to perhaps store the
VMOffsetsin theruntime_infofield since this information is statically known when the module is created and it can live in one location in the module and be referenced indirectly by each instance. The reason I hesitate to do this though is that accessing the vmoffsets would then become a dynamic function call (sinceModuleRuntimeInfois a trait). as opposed to today where information is at a static offset withinInstance. I'm worried about the runtime impact of naively moving this information behindModuleRuntimeInfo(sinceVMOffsetsis pretty hot).I'm not sure how best to solve this immediately, but some possibilities include:
- We could store a raw pointer, returned by
ModuleRuntimeInfo, intoInstanceso we call the indirect function once at construction and then never again.- The
ModuleRuntimeInfocould perhaps return anArc"package" of various other bits and pieces of information that don't need to go through a virtual lookup. Or otherwise we could do away with theModuleRuntimeInfotrait and instead have some sort of structure there which is precomputed for eachModule(this would be a large-ish refactoring).And possibly other strategies as well. Given the relatively low impact of having this stored in each instance though this isn't the most pressing issue.
Last updated: Dec 06 2025 at 06:05 UTC