Page MenuHomePhabricator

speed up Unserialize_impl for prevector
ClosedPublic

Authored by PiRK on Nov 11 2020, 11:41.

Details

Reviewers
majcosta
Group Reviewers
Restricted Project
Commits
rABC7289af88e992: speed up Unserialize_impl for prevector
Summary

The unserializer for prevector uses resize() for reserve the area,
but it's prefer to use reserve() because resize() have overhead
to call its constructor many times.

However, reserve() does not change the value of "_size"
(a private member of prevector).

This PR introduce resize_uninitialized() to prevector that similar to
resize() but does not call constructor, and added elements are
explicitly initialized in Unserialize_imple().

The changes are as follows:

  1. prevector.h

Add a public member function named 'resize_uninitialized'.
This function processes like as resize() but does not call constructors.
So added elemensts needs explicitly initialized after this returns.

  1. serialize.h

In the following two function:
Unserialize_impl(Stream& is, prevector<N, T>& v, const unsigned char&)
Unserialize_impl(Stream& is, prevector<N, T>& v, const V&)
Calls resize_uninitialized() instead of resize()

  1. test/prevector_tests.cpp

Add a test for resize_uninitialized().

Benchmark details provided in the PR discussion:

[Machine]
MacBook Pro (macOS 10.13.3/i7 2.2GHz/mem 16GB/SSD)

[result]
DeserializeAndCheckBlockTest => 22% faster
DeserializeBlockTest => 29% faster

This is a backport of Core PR12324

Test Plan

ninja all check-all

Diff Detail