0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00
bitcoin-core/src
Andrew Chow 5cce4d293e
Merge bitcoin/bitcoin#27334: util: implement noexcept move assignment & move ctor for prevector
bfb9291a86 util: implement prevector's move ctor & move assignment (Martin Leitner-Ankerl)
fffc86f49f test: CScriptCheck is used a lot in std::vector, make sure that's efficient (Martin Leitner-Ankerl)
81f67977f5 util: prevector's move ctor and move assignment is `noexcept` (Martin Leitner-Ankerl)
d380d2877e bench: Add benchmark for prevector usage in std::vector (Martin Leitner-Ankerl)

Pull request description:

  `prevector`'s move assignment and move constructor were not `noexcept`, which makes it inefficient to use inside STL containers like `std::vector`. That's the case e.g. for `CScriptCheck`. This PR adds `noexcept`, and also implements the move assignment & ctor, which makes it quite a bit more efficient to use prevector in an std::vector.

  The PR also adds a benchmark which grows an `std::vector` by adding `prevector` objects to it.

  merge-base:
  |               ns/op |                op/s |    err% |          ins/op |          cyc/op |    IPC |         bra/op |   miss% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
  |            6,440.29 |          155,272.42 |    0.2% |       40,713.01 |       20,473.84 |  1.989 |       7,132.01 |    0.2% |      0.44 | `PrevectorFillVectorDirectNontrivial`
  |            3,213.19 |          311,217.35 |    0.7% |       35,373.01 |       10,214.07 |  3.463 |       6,945.00 |    0.2% |      0.43 | `PrevectorFillVectorDirectTrivial`
  |           34,749.70 |           28,777.23 |    0.1% |      364,396.05 |      110,521.94 |  3.297 |      78,568.37 |    0.1% |      0.43 | `PrevectorFillVectorIndirectNontrivial`
  |           32,535.05 |           30,736.09 |    0.4% |      353,823.31 |      103,464.53 |  3.420 |      79,871.80 |    0.2% |      0.40 | `PrevectorFillVectorIndirectTrivial`

  util: prevector's move ctor and move assignment is `noexcept`:
  |               ns/op |                op/s |    err% |          ins/op |          cyc/op |    IPC |         bra/op |   miss% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
  |            6,603.87 |          151,426.40 |    0.2% |       23,734.01 |       21,009.63 |  1.130 |       2,445.01 |    0.3% |      0.44 | `PrevectorFillVectorDirectNontrivial`
  |            1,980.93 |          504,813.15 |    0.1% |       13,784.00 |        6,304.32 |  2.186 |       2,258.00 |    0.3% |      0.44 | `PrevectorFillVectorDirectTrivial`
  |           19,110.54 |           52,327.15 |    0.1% |      139,816.41 |       51,987.72 |  2.689 |      28,512.18 |    0.1% |      0.43 | `PrevectorFillVectorIndirectNontrivial`
  |           12,334.37 |           81,074.27 |    0.7% |      125,655.12 |       39,253.58 |  3.201 |      27,854.46 |    0.2% |      0.44 | `PrevectorFillVectorIndirectTrivial`

  util: implement prevector's move ctor & move assignment
  |               ns/op |                op/s |    err% |          ins/op |          cyc/op |    IPC |         bra/op |   miss% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
  |            5,262.66 |          190,018.01 |    0.2% |       20,157.01 |       16,745.26 |  1.204 |       2,445.01 |    0.3% |      0.44 | `PrevectorFillVectorDirectNontrivial`
  |            1,687.07 |          592,744.35 |    0.2% |       12,742.00 |        5,368.02 |  2.374 |       2,258.00 |    0.3% |      0.44 | `PrevectorFillVectorDirectTrivial`
  |           17,930.80 |           55,769.95 |    0.1% |      136,237.69 |       47,903.31 |  2.844 |      28,512.02 |    0.2% |      0.42 | `PrevectorFillVectorIndirectNontrivial`
  |           11,893.75 |           84,077.78 |    0.2% |      126,182.02 |       37,852.91 |  3.333 |      28,152.01 |    0.1% |      0.44 | `PrevectorFillVectorIndirectTrivial`

  As can be seen, mostly thanks to just `noexcept` the benchmark becomes about 2 times faster because `std::vector` can now use move operations instead of having to fall back to copy everything

  I had a look at how this change affects the other benchmarks, and they are all pretty much the same, the only noticable difference is `CCheckQueueSpeedPrevectorJob` goes from 364.56ns down to 346.21ns.

ACKs for top commit:
  achow101:
    ACK bfb9291a86
  jonatack:
    > Tested Approach ACK [bfb9291](bfb9291a86), ~ACK modulo re-verifying the implementation of the last commit.
  john-moffett:
    Approach ACK bfb9291a86
  theStack:
    Tested and light code-review ACK bfb9291a86

Tree-SHA512: 242995d7cb2f8ebfa73177aa690a505f189d91edeb8cea3e34a41ca507c8cb17c65fe2a4e196fdafc5c6e89b2b2222627bfc9f5c316517de0857b7b5e9c58225
2023-06-27 15:42:51 -04:00
..
bench Merge bitcoin/bitcoin#27334: util: implement noexcept move assignment & move ctor for prevector 2023-06-27 15:42:51 -04:00
common scripted-diff: Following the C++ Standard rules for identifiers with _. 2023-06-20 10:23:08 +02:00
compat refactor: don't avoid sys/types.h on when building for Windows 2023-04-03 14:44:48 +01:00
config
consensus Use int32_t type for most transaction size/weight values 2023-06-12 19:47:19 +01:00
crc32c
crypto scripted-diff: Use platform-agnostic ALWAYS_INLINE macro 2023-05-04 20:58:01 +01:00
index refactor: index: use AbortNode in fatal error helper 2023-06-08 16:38:36 -03:00
init init: remove config option names from translated -loglevel strings 2023-06-15 10:27:56 -06:00
interfaces Merge bitcoin/bitcoin#27708: Return EXIT_FAILURE on post-init fatal errors 2023-06-12 12:54:49 -04:00
ipc refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
kernel refactor: Make m_count_with_* in CTxMemPoolEntry int64_t, drop UBSAN supp 2023-06-14 23:15:20 +02:00
leveldb
logging Use steady clock for logging timer 2023-01-31 18:48:50 +01:00
minisketch
node Merge bitcoin/bitcoin#27862: validation: Stricter assumeutxo error handling when renaming chainstates 2023-06-22 13:20:36 -04:00
policy Merge bitcoin/bitcoin#27914: feerate: For GetFeePerK() return nSatoshisPerK instead of round trip through GetFee 2023-06-26 09:43:38 +01:00
primitives
qt Merge bitcoin/bitcoin#27708: Return EXIT_FAILURE on post-init fatal errors 2023-06-12 12:54:49 -04:00
rpc scripted-diff: Following the C++ Standard rules for identifiers with _. 2023-06-20 10:23:08 +02:00
script refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
secp256k1 Update src/secp256k1 subtree to version with ElligatorSwift support 2023-06-21 11:04:00 -04:00
support scripted-diff: Following the C++ Standard rules for identifiers with _. 2023-06-20 10:23:08 +02:00
test Merge bitcoin/bitcoin#27479: BIP324: ElligatorSwift integrations 2023-06-26 17:08:03 -04:00
univalue scripted-diff: Following the C++ Standard rules for identifiers with _. 2023-06-20 10:23:08 +02:00
util refactor: Avoid copy of bilingual_str when formatting, Fix ADL violation 2023-06-15 16:21:29 +02:00
wallet Merge bitcoin/bitcoin#27846: [coinselection] Increase SRD target by change_fee 2023-06-23 16:57:11 -04:00
zmq p2p, refactor: return std::optional<CNetAddr> in LookupHost 2023-05-26 13:41:07 -03:00
.bear-tidy-config
.clang-format
.clang-tidy clang-tidy: Exclude performance-* checks rather including them 2023-03-26 20:18:13 +01:00
addrdb.cpp scripted-diff: move settings to common namespace 2023-05-30 17:26:51 +02:00
addrdb.h fix includes for touched header files (iwyu) 2023-05-29 13:26:31 +02:00
addrman.cpp addrman: add functionality to select by network 2023-03-17 17:59:02 -07:00
addrman.h doc: clarify new_only param for Select function 2023-03-17 18:02:40 -07:00
addrman_impl.h addrman: add functionality to select by network 2023-03-17 17:59:02 -07:00
arith_uint256.cpp
arith_uint256.h Fix clang-tidy readability-const-return-type violations 2023-02-01 11:33:35 +01:00
attributes.h Introduce platform-agnostic ALWAYS_INLINE macro 2023-05-04 20:57:51 +01:00
banman.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
banman.h refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
base58.cpp
base58.h
bech32.cpp
bech32.h
bitcoin-chainstate.cpp kernel: Remove chainparams, chainparamsbase, args, settings from kernel library 2023-05-30 17:15:22 +02:00
bitcoin-cli-res.rc
bitcoin-cli.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
bitcoin-tx-res.rc
bitcoin-tx.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
bitcoin-util-res.rc
bitcoin-util.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
bitcoin-wallet-res.rc
bitcoin-wallet.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
bitcoind-res.rc
bitcoind.cpp refactor: decouple early return commands from AppInit 2023-06-10 11:10:29 -03:00
blockencodings.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
blockencodings.h script: remove out-of-date snprintf TODO 2023-02-15 14:42:28 -08:00
blockfilter.cpp refactor: use Hash helper for double-SHA256 calculations 2023-01-31 19:34:35 +01:00
blockfilter.h
chain.cpp
chain.h refactor: add kernel/cs_main.* 2023-01-05 09:05:14 +00:00
chainparams.cpp test: Throw error when -signetchallenge is non-hex 2023-05-25 19:24:05 +02:00
chainparams.h test: Throw error when -signetchallenge is non-hex 2023-05-25 19:24:05 +02:00
chainparamsbase.cpp refactor: Use ChainType enum exhaustively 2023-05-10 10:39:58 +02:00
chainparamsbase.h refactor: Use ChainType enum exhaustively 2023-05-10 10:39:58 +02:00
chainparamsseeds.h p2p: update hardcoded mainnet seeds for 25.x 2023-04-20 06:08:22 -07:00
checkqueue.h refactor: Use move semantics in CCheckQueue::Loop 2023-03-21 13:04:21 +00:00
clientversion.cpp
clientversion.h
coins.cpp Use PoolAllocator for CCoinsMap 2023-03-23 19:38:38 +01:00
coins.h Use PoolAllocator for CCoinsMap 2023-03-23 19:38:38 +01:00
compressor.cpp
compressor.h
core_io.h rpc: decode Miniscript descriptor when possible in decodescript 2023-02-03 18:15:42 +01:00
core_memusage.h
core_read.cpp Use DataStream where possible 2023-01-26 10:44:05 +01:00
core_write.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
cuckoocache.h clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
dbwrapper.cpp refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
dbwrapper.h refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
deploymentinfo.cpp Decouple RegTestChainParams from ArgsManager 2023-03-15 16:42:42 +01:00
deploymentinfo.h Decouple RegTestChainParams from ArgsManager 2023-03-15 16:42:42 +01:00
deploymentstatus.cpp
deploymentstatus.h
dummywallet.cpp move-only: Extract common/args and common/config.cpp from util/system 2023-04-19 10:48:30 +02:00
external_signer.cpp Fix clang-tidy performance-unnecessary-copy-initialization warnings 2023-05-09 18:48:52 +02:00
external_signer.h refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
flatfile.cpp refactor: Extract util/fs_helpers from util/system 2023-03-23 12:52:00 +01:00
flatfile.h Merge bitcoin/bitcoin#27254: refactor: Extract util/fs from util/system 2023-04-03 14:41:22 +01:00
hash.cpp
hash.h Merge bitcoin/bitcoin#26649: refactor: Use AutoFile and HashVerifier (without ser-type and ser-version) where possible 2023-01-30 15:57:12 +00:00
headerssync.cpp
headerssync.h
httprpc.cpp scripted-diff: Use UniValue::find_value method 2023-05-09 18:47:14 +02:00
httprpc.h
httpserver.cpp p2p, refactor: return std::optional<CNetAddr> in LookupHost 2023-05-26 13:41:07 -03:00
httpserver.h
i2p.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
i2p.h refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
indirectmap.h
init.cpp Merge bitcoin/bitcoin#27862: validation: Stricter assumeutxo error handling when renaming chainstates 2023-06-22 13:20:36 -04:00
init.h Return EXIT_FAILURE on post-init fatal errors 2023-06-09 17:52:23 -03:00
key.cpp Add ElligatorSwift key creation and ECDH logic 2023-06-23 14:22:33 -04:00
key.h Add ElligatorSwift key creation and ECDH logic 2023-06-23 14:22:33 -04:00
key_io.cpp use 'byte'/'bytes' for bech32(m) validation error 2023-05-25 06:30:10 +00:00
key_io.h
logging.cpp refactor: rename BCLog::BLOCKSTORE to BLOCKSTORAGE 2023-06-15 10:27:56 -06:00
logging.h refactor: rename BCLog::BLOCKSTORE to BLOCKSTORAGE 2023-06-15 10:27:56 -06:00
Makefile.am move-only: Move settings to the common library 2023-05-30 17:26:47 +02:00
Makefile.bench.include Bench test for EllSwift ECDH 2023-06-23 14:24:32 -04:00
Makefile.crc32c.include
Makefile.leveldb.include
Makefile.minisketch.include
Makefile.qt.include Build: Log when test -f fails in Makefile 2023-02-03 22:33:14 +01:00
Makefile.qt_locale.include qt: Periodic translation updates from Transifex 2023-02-27 13:53:29 +00:00
Makefile.qttest.include
Makefile.test.include fuzz: wallet, add target for CoinControl 2023-06-17 23:55:16 +05:30
Makefile.test_fuzz.include
Makefile.test_util.include Add pool based memory resource & allocator 2023-03-23 19:38:38 +01:00
Makefile.univalue.include
mapport.cpp Merge bitcoin/bitcoin#26261: p2p: cleanup LookupIntern, Lookup and LookupHost 2023-05-30 11:39:59 -04:00
mapport.h Remove configure-time setting of DEFAULT_UPNP 2023-01-28 15:24:13 +00:00
memusage.h Calculate memory usage correctly for unordered_maps that use PoolAllocator 2023-03-23 19:38:38 +01:00
merkleblock.cpp
merkleblock.h
net.cpp Merge bitcoin/bitcoin#27577: p2p: give seednodes time before falling back to fixed seeds 2023-06-23 17:39:58 -04:00
net.h net: remove unused CConnmanTest 2023-06-23 18:03:06 -03:00
net_permissions.cpp Merge bitcoin/bitcoin#26261: p2p: cleanup LookupIntern, Lookup and LookupHost 2023-05-30 11:39:59 -04:00
net_permissions.h
net_processing.cpp Merge bitcoin/bitcoin#27947: MaybePunishNodeForTx: Remove unused message arg and logging 2023-06-26 10:39:32 +01:00
net_processing.h Support up to 3 parallel compact block txn fetchings 2023-05-23 13:07:49 -04:00
net_types.cpp
net_types.h
netaddress.cpp Merge bitcoin/bitcoin#25619: net: avoid overriding non-virtual ToString() in CService and use better naming 2023-02-17 13:34:40 -05:00
netaddress.h Merge bitcoin/bitcoin#25619: net: avoid overriding non-virtual ToString() in CService and use better naming 2023-02-17 13:34:40 -05:00
netbase.cpp p2p, refactor: return std::optional<CNetAddr> in LookupHost 2023-05-26 13:41:07 -03:00
netbase.h p2p, refactor: return std::optional<CNetAddr> in LookupHost 2023-05-26 13:41:07 -03:00
netgroup.cpp
netgroup.h
netmessagemaker.h
noui.cpp
noui.h
outputtype.cpp Don't return OutputType::UNKNOWN in ParseOutputType 2023-04-16 23:48:05 +02:00
outputtype.h
pow.cpp
pow.h
prevector.h util: implement prevector's move ctor & move assignment 2023-03-26 15:49:52 +02:00
protocol.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
protocol.h doc: Remove unused NO_BLOOM_VERSION constant 2023-05-15 10:18:58 +02:00
psbt.cpp Merge bitcoin/bitcoin#25939: rpc: In utxoupdatepsbt also look for the tx in the txindex 2023-04-21 14:06:12 -04:00
psbt.h Merge bitcoin/bitcoin#25939: rpc: In utxoupdatepsbt also look for the tx in the txindex 2023-04-21 14:06:12 -04:00
pubkey.cpp Add ElligatorSwift key creation and ECDH logic 2023-06-23 14:22:33 -04:00
pubkey.h Fuzz test for Ellswift ECDH 2023-06-23 14:22:39 -04:00
random.cpp Bench test for EllSwift ECDH 2023-06-23 14:24:32 -04:00
random.h Bench test for EllSwift ECDH 2023-06-23 14:24:32 -04:00
randomenv.cpp refactor: don't avoid sys/types.h on when building for Windows 2023-04-03 14:44:48 +01:00
randomenv.h
rest.cpp rest: bugfix, fix crash error when calling /deploymentinfo 2023-06-12 10:24:14 -03:00
rest.h
reverse_iterator.h doc: remove usages of C++11 2023-01-12 13:42:44 +00:00
scheduler.cpp
scheduler.h
serialize.h clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
shutdown.cpp Return EXIT_FAILURE on post-init fatal errors 2023-06-09 17:52:23 -03:00
shutdown.h Return EXIT_FAILURE on post-init fatal errors 2023-06-09 17:52:23 -03:00
signet.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
signet.h
span.h Add ElligatorSwift key creation and ECDH logic 2023-06-23 14:22:33 -04:00
streams.h streams: Drop confusing DataStream::Serialize method and << operator 2023-06-01 10:27:33 -04:00
sync.cpp
sync.h doc: Export threadsafety.h from sync.h 2023-01-25 09:33:26 +01:00
threadsafety.h
timedata.cpp move-only: Extract common/args and common/config.cpp from util/system 2023-04-19 10:48:30 +02:00
timedata.h
tinyformat.h clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
torcontrol.cpp p2p, refactor: return vector/optional<CService> in Lookup 2023-05-26 13:40:02 -03:00
torcontrol.h refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
txdb.cpp refactor: Replace std::optional<bilingual_str> with util::Result 2023-05-24 08:55:47 -04:00
txdb.h fix includes for touched header files (iwyu) 2023-05-29 13:26:31 +02:00
txmempool.cpp refactor: Make m_count_with_* in CTxMemPoolEntry int64_t, drop UBSAN supp 2023-06-14 23:15:20 +02:00
txmempool.h Use int32_t type for most transaction size/weight values 2023-06-12 19:47:19 +01:00
txorphanage.cpp scripted-diff: Following the C++ Standard rules for identifiers with _. 2023-06-20 10:23:08 +02:00
txorphanage.h scripted-diff: Following the C++ Standard rules for identifiers with _. 2023-06-20 10:23:08 +02:00
txrequest.cpp Add public Boost headers explicitly 2023-05-31 15:43:01 +01:00
txrequest.h
uint256.cpp
uint256.h Added static_assert to check that base_blob is using whole bytes. 2023-06-22 01:31:06 +02:00
undo.h
validation.cpp Merge bitcoin/bitcoin#26828: assumeutxo: catch and log fs::remove error instead of two exist checks 2023-06-23 16:21:43 -04:00
validation.h Merge bitcoin/bitcoin#27334: util: implement noexcept move assignment & move ctor for prevector 2023-06-27 15:42:51 -04:00
validationinterface.cpp Fix clang-tidy readability-const-return-type violations 2023-02-01 11:33:35 +01:00
validationinterface.h refactor: add kernel/cs_main.* 2023-01-05 09:05:14 +00:00
version.h doc: Remove unused NO_BLOOM_VERSION constant 2023-05-15 10:18:58 +02:00
versionbits.cpp refactor: use braced init for integer constants instead of c style casts 2023-01-03 19:31:29 -06:00
versionbits.h
walletinitinterface.h
warnings.cpp refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
warnings.h