Stream: git-wasmtime

Topic: wasmtime / PR #15276 ResourceTable: expose ResourceTableE...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2026 at 22:25):

pchickey edited PR #15276.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2026 at 22:25):

pchickey edited PR #15276:

TableEntry is now pub ResourceTableEntry, with pub methods as getters to its contents. pub ResourceTableEntryMut<'_> is used as a wrapper for &mut ResourceTableEntry that allows keeps the assurance that internal parent/child invariants can't be broken by a mem::swap.

To aid debugging the ResourceTable, TableEntry contains the core::any::type_name<T>() of an entry. This adds 2 words (16 bytes) of overhead to each TableEntry, but this debugging concern has come up repeatedly over the years, so my personal judgement is that this is an acceptable cost.

ResourceTable::iter_mut has been changed to have Item = (u32, ResourceTableEntryMut<'_>) and new ResourceTable::iter is the same iterator with Item = (u32, &ResourceTableEntry) for immutable access. Both iterators will never yield a tombstone, which is an internal implementation detail, and ensures that .iter{_mut}().count() == .len(). ResourceTable::iter_entries and iter_children have also been updated to yield those types as well.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2026 at 22:26):

pchickey edited PR #15276:

TableEntry is now pub ResourceTableEntry, with pub methods as getters to its contents. pub ResourceTableEntryMut<'_> is used as a wrapper for &mut ResourceTableEntry that allows keeps the assurance that internal parent/child invariants can't be broken by a mem::swap.

To aid debugging the ResourceTable, TableEntry contains the core::any::type_name<T>() of an entry. This adds 2 words (16 bytes) of overhead to each TableEntry, but this debugging concern has come up repeatedly over the years, so my personal judgement is that this is an acceptable cost - maximum cost is 16M with the table size limit.

ResourceTable::iter_mut has been changed to have Item = (u32, ResourceTableEntryMut<'_>) and new ResourceTable::iter is the same iterator with Item = (u32, &ResourceTableEntry) for immutable access. Both iterators will never yield a tombstone, which is an internal implementation detail, and ensures that .iter{_mut}().count() == .len(). ResourceTable::iter_entries and iter_children have also been updated to yield those types as well.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2026 at 00:48):

github-actions[bot] added the label wasmtime:api on PR #15276.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2026 at 00:48):

github-actions[bot] added the label wasi on PR #15276.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2026 at 15:46):

:memo: rvolosatovs submitted PR review:

This makes sense to me, and I am not opposed to doing this, but perhaps somebody else could weigh in on this before we commit to the path of storing type name strings in all dynamic values?

Personally, if I wanted to iterate the contents of a resource table and answer the question of "what resource type is this" for each entry, I'd rather establish a mapping from TypeId to whatever it is that I am looking for, e.g. a &'static str in this case, and then do a lookup using type_id of the Any when e.g. iterating the table entries.

What do you think about:

  1. Since this is only used for debugging, gating the string behind debug_assertions? https://doc.rust-lang.org/reference/conditional-compilation.html#debug_assertions
  2. Instead of storing the type name along the entry, maintain a TypeId -> &'static str map? This could of course be prone to growing without a bound which could be fine especially if only present in debug builds (1.)

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2026 at 15:46):

rvolosatovs requested alexcrichton for a review on PR #15276.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2026 at 15:48):

:memo: rvolosatovs submitted PR review:

This makes sense to me, and I am not opposed to doing this, but perhaps somebody else could weigh in on this before we commit to the path of storing type name strings in all dynamic values? (like https://github.com/bytecodealliance/wasmtime/pull/15286)

Personally, if I wanted to iterate the contents of a resource table and answer the question of "what resource type is this" for each entry, I'd rather establish a mapping from TypeId to whatever it is that I am looking for, e.g. a &'static str in this case, and then do a lookup using type_id of the Any when e.g. iterating the table entries.

What do you think about:

  1. Since this is only used for debugging, gating the string behind debug_assertions? https://doc.rust-lang.org/reference/conditional-compilation.html#debug_assertions
  2. Instead of storing the type name along the entry, maintain a TypeId -> &'static str map? This could of course be prone to growing without a bound which could be fine especially if only present in debug builds (1.)

view this post on Zulip Wasmtime GitHub notifications bot (Nov 16 2026 at 16:01):

:thumbs_up: alexcrichton submitted PR review:

In terms of overhead, the best way to fix it IMO would be to make a module-local trait:

trait AnyWithTypeName: Any {
    fn type_name(&self) -> &'static str;
}

impl<T: Any> AnyWithTypeName for T {
    fn type_name(&self) -> &'static str { std::any::type_name(self) }
}

and then store Box<dyn AnyWithTypeName> within the table. That could still be exposed to users as &dyn Any` and such to keep the trait internal, but that would avoid having any more storage costs.

I will say though having a BTreeSet-per-entry is probably significantly more overhead than a &'static str, so it's also sort of six-to-one-half-dozen-or-the-other to me.

Overall though the API here looks reasonable to me

view this post on Zulip Wasmtime GitHub notifications bot (Nov 16 2026 at 16:02):

:thumbs_up: alexcrichton submitted PR review:

In terms of overhead, the best way to fix it IMO would be to make a module-local trait:

trait AnyWithTypeName: Any {
    fn type_name(&self) -> &'static str;
}

impl<T: Any> AnyWithTypeName for T {
    fn type_name(&self) -> &'static str { std::any::type_name(self) }
}

and then store Box<dyn AnyWithTypeName> within the table. That could still be exposed to users as &dyn Any and such to keep the trait internal, but that would avoid having any more storage costs.

I will say though having a BTreeSet-per-entry is probably significantly more overhead than a &'static str, so it's also sort of six-to-one-half-dozen-or-the-other to me.

Overall though the API here looks reasonable to me

view this post on Zulip Wasmtime GitHub notifications bot (Nov 16 2026 at 20:11):

pchickey commented on PR #15276:

I don't think debug_assertions is the right thing to gate this behind, because this is used so that embedders of wasmtime can allow their own users to debug their applications, and its reasonable that embedders will be shipping a release build to do so.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 16 2026 at 20:51):

pchickey updated PR #15276.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 16 2026 at 22:08):

pchickey added PR #15276 ResourceTable: expose ResourceTableEntry and any::type_name, update iterators to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 16 2026 at 22:29):

:check: pchickey merged PR #15276.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 16 2026 at 22:29):

pchickey removed PR #15276 ResourceTable: expose ResourceTableEntry and any::type_name, update iterators from the merge queue.


Last updated: Nov 19 2026 at 20:05 UTC