Stream: git-wasmtime

Topic: wasmtime / issue #9352 Avoid locks for subtyping checks i...


view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2024 at 19:27):

fitzgen added the cranelift:goal:optimize-speed label to Issue #9352.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2024 at 19:27):

fitzgen added the wasmtime:ref-types label to Issue #9352.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2024 at 19:27):

fitzgen added the performance label to Issue #9352.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2024 at 19:27):

fitzgen opened issue #9352:

Currently the TypeRegistry::is_subtype method requires taking a read lock to access the supertypes arrays that allow for O(1) subtype checking. At the time of writing, this doesn't power the ref.{test,cast} instructions because I haven't gotten around to implementing them yet, but it is expected that it will for the very first MVP implementation of them. It is also used in the id-to-funcref conversion for the funcrefs side table (see https://github.com/bytecodealliance/wasmtime/pull/9341).

Acquiring a lock during Wasm execution is, of course, not ideal for horizontal scaling within a process.

We can avoid locks for most cases by creating a shared lock-free arena of supertype indices (potentially built on top of a linear memory) where the arena's free list and mapping of type id to pointer-to-supertype-array are behind a lock, but accessing already-allocated supertypes arrays doesn't require any locking. (The supertypes arrays are immutable for as long as they exist, which makes accessing them without locking safe.)

(Actually, as I write this out, this is basically what we are doing in TypeRegistry today already, except we're allocating supertypes arrays via the global allocator and they aren't all in the same shared arena. But there is no reason why we couldn't start exposing the pointers to the supertypes arrays to Wasm today, modulo some #[repr(C)] sprinkling and a few little things like that).

Our various operations would then proceed as follows:


Last updated: Oct 23 2024 at 20:03 UTC