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 make the logic of read from stream to callback function, and prevector handles initilizing new values with that call-back and ajust the value of _size
.
The changes are as follows:
-
prevector.h Add a public member function named ‘append’. This function has 2 params, number of elemenst to append and call-back function that initilizing new appended values.
-
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&)
Make a callback function from each original logic of reading values from stream, and call prevector’sappend()
.
- test/prevector_tests.cpp
Add a test for
append()
.
A benchmark result is following:
[Machine] MacBook Pro (macOS 10.13.3/i7 2.2GHz/mem 16GB/SSD)
[result] DeserializeAndCheckBlockTest => 22% faster DeserializeBlockTest => 29% faster
[before PR] # Benchmark, evals, iterations, total, min, max, median DeserializeAndCheckBlockTest, 60, 160, 94.4901, 0.0094644, 0.0104715, 0.0098339 DeserializeBlockTest, 60, 130, 65.0964, 0.00800362, 0.00895134, 0.00824187
[After PR] # Benchmark, evals, iterations, total, min, max, median DeserializeAndCheckBlockTest, 60, 160, 77.1597, 0.00767013, 0.00858959, 0.00805757 DeserializeBlockTest, 60, 130, 49.9443, 0.00613926, 0.00691187, 0.00635527