Commit 662768f3 authored by Jeremy Lilley's avatar Jeremy Lilley Committed by Facebook Github Bot

Fix serializedSizeZC() for IOBufQueue "packed" behavior & document

Summary:
Recently, IOBufQueue started "packing" smaller IOBufs (i.e. <= 4KB) when serializing.
This was helpful to avoid unnecessarily IOBuf chaining.

That said, we did not update our serializedSizeZC() functions to emit an accurate
memory estimate in the case that we did need to pack the IOBuf data. This changes
to pass though the IOBuf size, if under the threshold.

Also, add a few basic comments in the Protocol implementations about what
serializedSize() means, because it's not entirely obvious to a new user that
the results aren't intended to be accurate. And document what "ZC" is intended for.

Reviewed By: yfeldblum

Differential Revision: D14919060

fbshipit-source-id: 18e9bd0c6b9e40ccd1006cffba36363c6f95ea41
parent 201b0af5
......@@ -30,7 +30,6 @@ using folly::IOBuf;
const size_t MIN_ALLOC_SIZE = 2000;
const size_t MAX_ALLOC_SIZE = 8000;
const size_t MAX_PACK_COPY = 4096;
/**
* Convenience function to append chain src to chain dst.
......@@ -41,10 +40,10 @@ void appendToChain(unique_ptr<IOBuf>& dst, unique_ptr<IOBuf>&& src, bool pack) {
} else {
IOBuf* tail = dst->prev();
if (pack) {
// Copy up to MAX_PACK_COPY bytes if we can free buffers; this helps
// Copy up to kMaxPackCopy bytes if we can free buffers; this helps
// reduce wastage (the tail's tailroom and the head's headroom) when
// joining two IOBufQueues together.
size_t copyRemaining = MAX_PACK_COPY;
size_t copyRemaining = folly::IOBufQueue::kMaxPackCopy;
std::size_t n;
while (src && (n = src->length()) <= copyRemaining &&
n <= tail->tailroom()) {
......@@ -164,7 +163,7 @@ void IOBufQueue::append(const folly::IOBuf& buf, bool pack) {
chainLength_ += buf.computeChainDataLength();
}
size_t copyRemaining = MAX_PACK_COPY;
size_t copyRemaining = kMaxPackCopy;
std::size_t n;
const folly::IOBuf* src = &buf;
folly::IOBuf* tail = head_->prev();
......
......@@ -532,6 +532,8 @@ class IOBufQueue {
IOBufQueue(IOBufQueue&&) noexcept;
IOBufQueue& operator=(IOBufQueue&&);
static constexpr size_t kMaxPackCopy = 4096;
private:
std::unique_ptr<folly::IOBuf> split(size_t n, bool throwOnUnderflow);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment