Open fitzgen opened 1 month ago
cc @fitzgen
.github/subscribe-to-label.json
configuration file.
[Learn more.](https://github.com/bytecodealliance/subscribe-to-label-action)
@cfallin and I were just brainstorming on this problem and came up with a couple interesting ideas.
VMFuncRef
s inside a store are allocated within an arena in that store. all VMFuncRef
s for the store, so instead of putting an module's funcref
s in the instance's vmctx
, they would be allocated into this arena.*mut VMFuncRef
s inside the GC heap, without trusting the GC heap, by bounds checking that the pointer is within that arena and appropriately aligned on every field/element read from a GC objectThe tricky part is that this arena can't be resized or else existing pointers are invalidated. So we would have to rely on pre-allocating (virtual) memory, and not allow passing new, dynamically-created wasmtime::Func
s to Wasm beyond that pre-allocated limit.
Expose the id-to-funcref slab to Wasm, as described above. (Potentially not useing wasmtime::Slab
anymore, but instead some simpler type that is more easily exposed to Wasm code.)
But instead of worrying about interning and/or wasting space and/or doing GC to clean up unused entries, we do the following:
id: Option<FuncRefId>
field to VMFuncRef
funcref
-to-id conversion:
(*funcref).id
is some, then we reuse the existing idfuncref
into the side table (or just push onto the slab directly in Wasm code) and set the id
field to the new entry's index
We don't keep
VMFuncRef
pointers inside the GC heap, as the GC heap is untrusted, and instead have a side table, and store table IDs in GC objects. We currently use libcalls to do id-to-funcref conversion when reading afuncref
out from a GC object and to intern afuncref
and get its associated table ID when writing thefuncref
into a GC object. libcalls on field/element access are very much not ideal from a performance perspective.I wrote up some thoughts on how we could improve the situation in the original PR:
Originally posted by @fitzgen in https://github.com/bytecodealliance/wasmtime/issues/9341#issuecomment-2386456719