X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fio%2FCompression.cpp;h=c692895f4d763b70f1388473944eedb44bba1d1e;hp=ae6adf7e8c78e949a8e521bd0d44076db0b5f639;hb=7f2dce7009e8575814d3e51c3fd3f124aa8228dd;hpb=8a7669993ede67715812371a5cbb29d6c5eb24be diff --git a/folly/io/Compression.cpp b/folly/io/Compression.cpp index ae6adf7e..c692895f 100644 --- a/folly/io/Compression.cpp +++ b/folly/io/Compression.cpp @@ -846,6 +846,13 @@ std::unique_ptr ZlibCodec::doCompress(const IOBuf* data) { return out; } +static uint64_t computeBufferLength(uint64_t const compressedLength) { + constexpr uint64_t kMaxBufferLength = uint64_t(4) << 20; // 4 MiB + constexpr uint64_t kBlockSize = uint64_t(32) << 10; // 32 KiB + const uint64_t goodBufferSize = 4 * std::max(kBlockSize, compressedLength); + return std::min(goodBufferSize, kMaxBufferLength); +} + std::unique_ptr ZlibCodec::doUncompress(const IOBuf* data, uint64_t uncompressedLength) { z_stream stream; @@ -878,8 +885,9 @@ std::unique_ptr ZlibCodec::doUncompress(const IOBuf* data, }; // Max 64MiB in one go - constexpr uint32_t maxSingleStepLength = uint32_t(64) << 20; // 64MiB - constexpr uint32_t defaultBufferLength = uint32_t(4) << 20; // 4MiB + constexpr uint64_t maxSingleStepLength = uint64_t(64) << 20; // 64MiB + const uint64_t defaultBufferLength = + computeBufferLength(data->computeChainDataLength()); auto out = addOutputBuffer( &stream,