Add memcpy-based i8 array constructor and reader to ArrayRef#13716
Open
somdoron wants to merge 1 commit into
Open
Add memcpy-based i8 array constructor and reader to ArrayRef#13716somdoron wants to merge 1 commit into
somdoron wants to merge 1 commit into
Conversation
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.
Subscribe to Label Actioncc @fitzgen DetailsThis 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:
To subscribe or unsubscribe from this label, edit the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.