Skip to content

feat: support deserializing to memoryview - #624

Merged
jcrist merged 4 commits into
msgspec:mainfrom
SunDoge:decode-memoryview
Jan 5, 2024
Merged

jcrist merged 4 commits into
msgspec:mainfrom
SunDoge:decode-memoryview

Conversation

@SunDoge

@SunDoge SunDoge commented Jan 4, 2024

Copy link
Copy Markdown
Contributor

The implementation enables zero-copy functionality when decoding msgpack by supporting deserialization directly to a memoryview. This is very useful for decoding large numpy array.

SunDoge and others added 4 commits January 4, 2024 11:25
This adds native support for memoryview fields. In most protocols this
offers no benefit over a `bytes`/`bytearray` field, but in the `msgpack`
decoder `memoryview` annotated fields will decode as a view into the
underlying message buffer, providing a direct zero-copy reference.
@jcrist

jcrist commented Jan 5, 2024

Copy link
Copy Markdown
Member

Thanks for the PR! I've taken the liberty to finish it up - adding support for new types needs to be done in several places.

Note that zero-copy deserialization of buffers can also be handled through Ext types. When decoding an Ext, the buffer passed to ext_hook is a memoryview into the original backing message. This was intended to support decoding large buffer-backed objects (like numpy arrays) in a zero-copy fashion.

@jcrist
jcrist merged commit fc75a28 into msgspec:main Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants