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.
Summary:
This sets us up for the next diff by creating
FragmentedPartCurrently our pickle is still not truly zero copy because the Pickler calls
Buffer::write()which is copying bytes fromPyBytestoBytesMutviaextend_from_slice().This is especially problematic for large messages (100KB+) as we are spending a lot of CPU cycles handling page faults. For a 1MB message pickling can take as long as 600us
To avoid copies, we can just make
Bufferbacked by aVec<PyBytes>with each call toBuffer::write()pushing the PyBytes to the Vec. As a result of this, the PyBytes are physically fragmented despite being logically contiguous.To make this work, we will have a NewType with called
FragmentedPartwith a::Fragmentedvariant wrappingVec<Part>and a::Contiguousvariant wrappingPart. Similar toPart,FragmentedPartalso just collects during serialization. When we receive the frame on the other end of the wire, we reconstruct it contiguously in theFragmentedPart::Contiguousvariant so that we can easily consume it to create a single contiguousbytes::BytesDifferential Revision: D86696390