Skip to content

Commit

Permalink
Document new memoryview behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Jan 5, 2024
1 parent c945ab7 commit 19a37da
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/source/supported-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,23 @@ Bytes-like objects map to base64-encoded strings in JSON, YAML, and TOML. The
>>> msgspec.json.decode(msg, type=bytearray)
bytearray(b'\xf0\x9d\x84\x9e')
.. note::

For the ``msgpack`` protocol, `memoryview` objects will be decoded as
direct views into the larger buffer containing the input message being
decoded. This may be useful for implementing efficient zero-copy handling
of large binary messages, but is also a potential footgun. As long as a
decoded ``memoryview`` remains in memory, the input message buffer will
also be persisted, potentially resulting in unnecessarily large memory
usage. The usage of ``memoryview`` types in this manner is considered an
advanced topic, and should only be used when you know their usage will
result in a performance benefit.

For all other protocols `memoryview` objects will still result in a copy,
and will likely be slightly slower than decoding into a `bytes` object


``datetime``
------------

Expand Down

0 comments on commit 19a37da

Please sign in to comment.