8000 [Upstream] [Core] Prevector by lyricidal · Pull Request #248 · PRCYCoin/PRCYCoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

8000 [Upstream] [Core] Prevector #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 15, 2022
Merged

Conversation

lyricidal
Copy link

Based on:

This introduces prevector<N, T>, a new basic data type which is a fully API compatible drop-in replacement for std::vector<T> and uses it for the script, to reduce the considerable memory overhead of vectors in cases where they normally contain a small number of small elements.

Original tests in Bitcoin showed a reduction in dbcache memory usage by 23%, and made an initial sync 13% faster.

Backported from the following upstream's PRs, with only additional edits in the 2nd layer scripts (masternode-payments, masternode-budget) and in the unit tests (to address the differences in insecure_rand):

NOTE: Updates to memusage.h needed as well, when #1531 is merged.

from PIVX-Project/PIVX#1557

additional info:

  • our payee is a std::vector<unsigned char> vs a CScript - adapted in ddba851 - leads to a memory error if not done

Fixes a bug in which pop_back did not call the deleted item's
destructor.

Using the most general erase() implementation to implement all the
others
prevents similar bugs because the coupling between deallocation and
destructor
invocation only needs to be maintained in one place.
Also reduces duplication of complex memmove logic.

backports bitcoin/bitcoin@1e2c29f
swap was using an incorrect condition to determine when to apply an
optimization
(not swapping the full direct[] when swapping two indirect prevectors).

Rather than correct the optimization I'm removing it for simplicity.
Removing
this optimization minutely improves performance in the typical
(currently only)
usage of member swap(), which is swapping with a freshly
value-initialized
object.

backports bitcoin/bitcoin@a7af72a
- add a swap operation to prevector tests (fails due to broken
prevector::swap)
- fix 2 prevector test operation conditions that were impossible

backports bitcoin/bitcoin@4ed41a2
This returns a pointer to the beginning of the vector's data.

backports bitcoin/bitcoin@47314e6
Implement `begin_ptr` and `end_ptr` in terms of C++11 code,
and add a comment that they are deprecated.

backports bitcoin/bitcoin@f00705a
Such moves are used when reallocating vectors that contain them,
for example.

backports bitcoin/bitcoin@2ddfcfd
@lyricidal lyricidal added the Upstream Upstream backports/fixes label Aug 15, 2022
@lyricidal lyricidal merged commit b057276 into develop Aug 15, 2022
@lyricidal lyricidal deleted the upstream-prevector-pr1557-updated branch August 15, 2022 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Upstream Upstream backports/fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0