Page MenuHomePhabricator

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

Authored by deadalnix on Sep 30 2018, 19:09.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

deadalnix edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Oct 1 2018, 21:50
This revision was automatically updated to reflect the committed changes.