alexcrichton opened issue #4191:
Currently whenever an instance is created Wasmtime will calculate the
VMOffsets
structure (also for the pooling allocator). ThisVMOffsets
structure which is actually quite large is also stored within theInstance
allocation 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
VMOffsets
in theruntime_info
field 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 (sinceModuleRuntimeInfo
is 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
(sinceVMOffsets
is 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
, intoInstance
so we call the indirect function once at construction and then never again.- The
ModuleRuntimeInfo
could 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 theModuleRuntimeInfo
trait 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
VMOffsets
structure (also for the pooling allocator). ThisVMOffsets
structure which is actually quite large is also stored within theInstance
allocation 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
VMOffsets
in theruntime_info
field 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 (sinceModuleRuntimeInfo
is 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
(sinceVMOffsets
is 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
, intoInstance
so we call the indirect function once at construction and then never again.- The
ModuleRuntimeInfo
could 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 theModuleRuntimeInfo
trait 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
VMOffsets
structure (also for the pooling allocator). ThisVMOffsets
structure which is actually quite large is also stored within theInstance
allocation 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
VMOffsets
in theruntime_info
field 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 (sinceModuleRuntimeInfo
is 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
(sinceVMOffsets
is 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
, intoInstance
so we call the indirect function once at construction and then never again.- The
ModuleRuntimeInfo
could 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 theModuleRuntimeInfo
trait 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: Nov 22 2024 at 16:03 UTC