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

WIP: Use bytearray in serialization #3918

Closed

Conversation

jakirkham
Copy link
Member

@jakirkham jakirkham commented Jun 22, 2020

Requires PR ( #3960 )

Make sure we use bytearrays for frames in merge_frames. This is needed to ensure we have frames that are writable as opposed to bytes, which is readonly.

xref: #1978 (comment)

@jakirkham jakirkham force-pushed the use_bytearray_in_serialization branch from 2dc7bd2 to b73dcd6 Compare June 22, 2020 22:00
@jakirkham jakirkham force-pushed the use_bytearray_in_serialization branch from b73dcd6 to cfa21ab Compare July 14, 2020 00:43
As the frames we receive are typically mutable, non-`bytes` objects like
`bytearray`s or NumPy `ndarray`s, coercing to `bytes` at this stage
triggers a copy of all frames. As we are going to toss those copied
versions anyways when joining them into a larger `bytes` object, this
ends up being wasteful with memory. Fortunately `bytes.join(...)`
accepts any and all `bytes`-like objects. So instead just pass them all
through as-is to `bytes.join(...)`, which is free and doesn't require a
copy.  Should cutdown on the memory usage in this part of the code.
@jakirkham jakirkham force-pushed the use_bytearray_in_serialization branch 2 times, most recently from 17eafa6 to afe02a1 Compare July 14, 2020 02:45
Instead of using `b""`, create the `bytes` object explicitly.
Instead of using a `bytes` object to merge frames together, use a
`bytearray`. This ensures the result is mutable, which downstream
objects from serialization may care about.
Provides a utility method to coerce the input into a `bytearray`
(copying if needed).
@jakirkham jakirkham force-pushed the use_bytearray_in_serialization branch from afe02a1 to 8f34e7f Compare July 14, 2020 02:54
@jakirkham
Copy link
Member Author

Superseded by PR ( #3967 ).

@jakirkham jakirkham closed this Jul 17, 2020
@jakirkham jakirkham deleted the use_bytearray_in_serialization branch July 17, 2020 19:27
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.

1 participant