From 6bb90698a194d181f9e0d962cd4eb622a1a5290a Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Wed, 12 Apr 2017 12:44:56 -0700 Subject: [PATCH] Fix zlib + lzma memory usage inefficiency Summary: Since IOBuf rounds to a good malloc size, zlib and lzma waste space. For a 4 MiB `length`, about 1 MiB of the IOBuf is wasted. Reviewed By: yfeldblum Differential Revision: D4872830 fbshipit-source-id: 42fc83277b2dae22b75403e0e71c43e8f2b19f21 --- folly/io/Compression.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/folly/io/Compression.cpp b/folly/io/Compression.cpp index ae75b2a6..4a9deaaf 100644 --- a/folly/io/Compression.cpp +++ b/folly/io/Compression.cpp @@ -840,7 +840,7 @@ std::unique_ptr ZlibCodec::addOutputBuffer(z_stream* stream, CHECK_EQ(stream->avail_out, 0); auto buf = IOBuf::create(length); - buf->append(length); + buf->append(buf->capacity()); stream->next_out = buf->writableData(); stream->avail_out = buf->length(); @@ -1147,7 +1147,7 @@ std::unique_ptr LZMA2Codec::addOutputBuffer( CHECK_EQ(stream->avail_out, 0); auto buf = IOBuf::create(length); - buf->append(length); + buf->append(buf->capacity()); stream->next_out = buf->writableData(); stream->avail_out = buf->length(); -- 2.34.1