Skip to content

Support bulk lowering for list<flat T> in dynamic component calls #13788

Description

@jeffparsons

I have a use case where I want to store collections of canonical-ABI-shaped component values in host memory, and then pass them in bulk to guest component functions.

Crucially, the host has no static knowledge of the component model types involved. The relevant WIT/component types are discovered at runtime. The host also never directly constructs the individual elements in a type-aware way: they are produced by guests that do have static knowledge of those component model types, then stored by the host as opaque bytes associated with reflected component-model type information.

Right now, as far as I can tell, there is no component-oriented way to dynamically call a guest function with an argument like “a list<T> whose elements are already available as contiguous canonical-ABI-layout bytes,” without recursively constructing something like Val::List(Vec<Val>) and paying per-element dynamic lowering overhead.

What I’m imagining is a Wasmtime API, either as a new kind of dynamic call function or as a special dynamic value representation, that would support bulk lowering for a restricted case:

  • the argument is a list<T>;
  • T is known through Wasmtime’s reflected component type information;
  • Wasmtime verifies that T is safe to bulk-copy in this way, for example because it has a fixed canonical ABI layout and contains no transitive strings, lists, resources, handles, or other pointer/ownership-bearing values;
  • Wasmtime computes the element size/stride/alignment from its own canonical ABI metadata;
  • the source byte slice length is checked against the computed element stride; and
  • Wasmtime allocates/copies the data into the callee’s linear memory using the normal component/canonical-ABI machinery.

The goal is not to expose an unchecked “raw bytes can be any component value” escape hatch. I’m looking for a checked fast path for the flat/fixed-size case, where the current dynamic Val API is semantically appropriate but forces avoidable per-element boxing/lowering work for large lists.

Would the Wasmtime project be open to supporting this use case in some form?

This seems related to broader requests for lower-overhead dynamic component calls, but the intended scope here is narrower than a fully unchecked component-call API: only bulk lowering/lifting for list<T> where T is a reflected, fixed-size, canonical-ABI-flat element type.

Edit: My specific use case is about trying to make a Wasm Component native archetypal ECS, but I wonder if there might be other, less "fringe" use cases for such a mechanism.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasm-proposal:component-modelIssues related to the WebAssembly Component Model proposal

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions