HomePhabricator

Make prevector::resize() and other prevector operations much faster

Description

Make prevector::resize() and other prevector operations much faster

Summary:

  • Add new prevector benchmarks.

This prepares for a series of two additional commits which optimize
prevector performance.

  • Reduce redundant code of prevector and speed it up

In prevector.h, the code which like item_ptr(size()) apears in the loop.
Both item_ptr() and size() judge whether values are held directly or
indirectly, but in most cases it is sufficient to make that judgement
once outside the loop.

This PR adds 2 private function fill() which has the loop to initialize
by specified value (or iterator of the other prevector's element),
but don't call item_ptr() in their loop.
Other functions(assign(), constructor, operator=(), insert())
that has similar loop, call fill() instead of original loop.

Also, resize() was changed like fill(), but it calls the default
constructor for that element each time.

  • Use memset() to optimize prevector::resize()

Further optimize prevector::resize() (which is called by a number of
other prevector methods) to use memset to initialize memory when the
prevector contains trivial types.

  • fix bench/prevector.cpp

PREVECTOR_TEST()
PREVECTOR_TEST macro should to call both
PrevectorXX<nontrivial_t>(state) and PrevectorXX<trivial_t>(state)
by specific "name" which given by parameter instead of calling
PrevectorResize<>() regardless of "name".
This patch changes "PrevectorResize<" of this macro to
"Prevector ## name<".

This is a backport of Core PR12549 and PR13598

Depends on D1844

Test Plan:

make check

Reviewers: #bitcoin_abc, schancel

Reviewed By: #bitcoin_abc, schancel

Subscribers: teamcity

Differential Revision: https://reviews.bitcoinabc.org/D1849

Details

Provenance
Evan Klitzke <evan@eklitzke.org>Authored on Feb 27 2018, 02:45
deadalnixCommitted on Oct 3 2018, 13:05
deadalnixPushed on Oct 3 2018, 13:05
Reviewer
Restricted Project
Differential Revision
D1849: Make prevector::resize() and other prevector operations much faster
Parents
rABC578cb2faa557: Tests: Improve benchmark precision
Branches
Unknown
Tags
Unknown