so it turns out that everything is always Bytes #1015
Closed
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.
Currently, the
http_box::BoxBody
type erases both the type of thehttp_body::Body
and theBody::Data
associated type (toBox<dyn Buf + Send>
). However, it turns out that erasing theData
type isn't actually necessary: all
Body
types in Linkerd useBytes
as theData
type.This branch changes
BoxBody
to just require thatB::Data
isBytes
,and always produce
Bytes
as its data type. This will enable a muchmore performant implementation of request body buffering for POST
retries (linkerd/linkerd2#6130). Rather than copying all the bytes from
a
dyn Buf
Data
type into an additional buffer, we can just clone theBytes
, increasing the reference count for that buffer, and return theoriginal
Bytes
. This means we don't need to perform additional memcpysto buffer bodies for retries; we just hold onto the already-allocated
Bytes
buffers.The cloned
Bytes
can then be stored in a vector, and if we have towrite them out again for a retry, we can do one big vectored write :)