Skip to content

Add memcpy-based i8 array constructor and reader to ArrayRef#13716

Open
somdoron wants to merge 1 commit into
bytecodealliance:mainfrom
somdoron:array-i8-slice
Open

Add memcpy-based i8 array constructor and reader to ArrayRef#13716
somdoron wants to merge 1 commit into
bytecodealliance:mainfrom
somdoron:array-i8-slice

Conversation

@somdoron

Copy link
Copy Markdown

Building a GC array of bytes from the host currently has to go through ArrayRef::new_fixed, which takes a slice of Val (32 bytes each) and writes one element at a time — a big transient allocation plus a per-element decode, with no faster path.

This adds new_from_i8_slice (+ async) and copy_to_i8_slice, which take a slice of u8 and fill/read the element body in a single memcpy, bypassing Val.

Building a GC arrayref of bytes from host code today goes through
ArrayRef::new_fixed, which takes a &[Val] (32 bytes each) and writes the
elements one Val at a time. For a host bridging byte buffers into GC
arrays (streaming I/O, codecs, etc.) that's a large transient allocation
plus a per-element decode, and there's no faster path.

Add ArrayRef::new_from_i8_slice / new_from_i8_slice_async, which take a
&[u8] and fill the element body in a single memcpy, plus copy_to_i8_slice
for the reverse. Both bypass Val entirely.

This only covers i8 arrays for now: byte buffers are by far the most
common case, and i8 needs no endianness handling, so the slice maps
directly onto the heap layout with no unsafe. Wider element types can be
added later on top of this.
@somdoron somdoron requested a review from a team as a code owner June 23, 2026 14:12
@somdoron somdoron requested review from pchickey and removed request for a team June 23, 2026 14:12
@github-actions github-actions Bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime labels Jun 23, 2026
@github-actions

Copy link
Copy Markdown

Subscribe to Label Action

cc @fitzgen

Details This issue or pull request has been labeled: "wasmtime:api", "wasmtime:ref-types"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: wasmtime:ref-types

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant