WIP: Use bytearray in serialization#3918
Closed
jakirkham wants to merge 8 commits intodask:masterfrom
Closed
Conversation
2dc7bd2 to
b73dcd6
Compare
b73dcd6 to
cfa21ab
Compare
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.
17eafa6 to
afe02a1
Compare
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).
afe02a1 to
8f34e7f
Compare
Member
Author
|
Superseded by PR ( #3967 ). |
Merged
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.
Requires PR ( #3960 )
Make sure we use
bytearrays for frames inmerge_frames. This is needed to ensure we have frames that are writable as opposed tobytes, which is readonly.xref: #1978 (comment)