Fix buffer allocation performance bugs

The code was using wrong Boost function for allocating char[]. The right
methods are make_shared_noinit and allocate_shared_noinit. The methods
w/o _noinit suffix initialize every element of the allocated array which
obviously is unneeded and has a horrific performance impact.

The bug impacted OutputBuffer, and thus typically serialization, blob
merging and Simple Json deserialization of blobs.
This commit is contained in:
Adam Sapek 2015-09-24 13:18:57 -07:00
Родитель f0301997e4
Коммит be41d67a53
4 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -291,7 +291,7 @@ inline blob merge(const A& allocator, const blob& x, const blob& y)
else
{
uint32_t length = x.length() + y.length();
boost::shared_ptr<char[]> buffer = boost::allocate_shared<char[]>(allocator, length);
boost::shared_ptr<char[]> buffer = boost::allocate_shared_noinit<char[]>(allocator, length);
::memcpy(buffer.get(), x.content(), x.length());
::memcpy(buffer.get() + x.length(), y.content(), y.length());
@ -334,7 +334,7 @@ inline blob merge(const A& allocator, t_It begin, t_It end)
//
BOOST_ASSERT(length > begin->length());
boost::shared_ptr<char[]> buffer = boost::allocate_shared<char[]>(allocator, length);
boost::shared_ptr<char[]> buffer = boost::allocate_shared_noinit<char[]>(allocator, length);
uint32_t offset = 0;
for (t_It it = begin; it != end; ++it)

Просмотреть файл

@ -56,7 +56,7 @@ inline void DeserializeContainer(blob& var, const T& /*element*/, SimpleJsonRead
{
if (uint32_t size = reader.ArraySize())
{
boost::shared_ptr<char[]> buffer = boost::make_shared<char[]>(size);
boost::shared_ptr<char[]> buffer = boost::make_shared_noinit<char[]>(size);
uint32_t i = 0;
for (rapidjson::Value::ConstValueIterator it = reader.ArrayBegin(), end = reader.ArrayEnd(); it != end && i < size; ++it)

Просмотреть файл

@ -119,7 +119,7 @@ public:
uint32_t minChanningSize = 32,
uint32_t maxChainLength = (uint32_t)-1)
: _allocator(allocator),
_buffer(boost::allocate_shared<char[]>(_allocator, reserveSize)),
_buffer(boost::allocate_shared_noinit<char[]>(_allocator, reserveSize)),
_bufferSize(reserveSize),
_rangeSize(0),
_rangeOffset(0),
@ -238,7 +238,7 @@ public:
_bufferSize += _bufferSize ? _bufferSize / 2 : 4096;
_bufferSize = (std::max)(_bufferSize, size);
_buffer = boost::allocate_shared<char[]>(_allocator, _bufferSize);
_buffer = boost::allocate_shared_noinit<char[]>(_allocator, _bufferSize);
//
// init range

Просмотреть файл

@ -57,7 +57,7 @@ public:
void Read(bond::blob& blob, uint32_t size)
{
boost::shared_ptr<char[]> buffer = boost::make_shared<char[]>(size);
boost::shared_ptr<char[]> buffer = boost::make_shared_noinit<char[]>(size);
Read(buffer.get(), size);
blob.assign(buffer, 0, size);