Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support deserializing to memoryview #624

Merged
merged 4 commits into from
Jan 5, 2024

Conversation

SunDoge
Copy link
Contributor

@SunDoge SunDoge commented Jan 4, 2024

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
Copy link
Owner

jcrist commented Jan 5, 2024

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 jcrist:main Jan 5, 2024
8 checks passed
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