aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2024-05-23 10:52:40 -0400
committerRyan Ofsky <ryan@ofsky.org>2024-05-23 10:53:37 -0400
commit6300438a2e0b6ee21fe210072b7b8be2f4845c17 (patch)
tree6d83d7b93ba30f11835e193ff5f60eafd40ea539 /src/test
parente163d864d380956a4c0f89a4d80a76f5aefc9a08 (diff)
parentd7707d9843b03f20d2a8c5a45d7b3db58e169e6f (diff)
Merge bitcoin/bitcoin#30115: rpc: avoid copying into UniValue
d7707d9843b03f20d2a8c5a45d7b3db58e169e6f rpc: avoid copying into UniValue (Cory Fields) Pull request description: These are the simple (and hopefully obviously correct) copies that can be moves instead. This is a follow-up from https://github.com/bitcoin/bitcoin/pull/30094#issuecomment-2108751842 As it turns out, there are hundreds of places where we copy UniValues needlessly. It should be the case that moves are always preferred over copies, so there should be no downside to these changes. willcl-ark, however, noticed that memory usage may increase in some cases. Logically this makes no sense to me. The only plausible explanation imo is that because the moves are faster, more ops/second occur in some cases. This list of moves was obtained by changing the function signatures of the UniValue functions to accept only rvalues, then compiling and fixing them up one by one. There still exist many places where copies are being made. These can/should be fixed up, but weren't done here for the sake of doing the easy ones first. I ran these changes through clang-tidy with `performance-move-const-arg` and `bugprone-use-after-move` and no bugs were detected (though that's obviously not to say it can be trusted 100%). As stated above, there are still lots of other less trivial fixups to do after these including: - Using non-const UniValues where possible so that moves can happen - Refactoring code in order to be able to move a UniValue without introducing a use-after-move - Refactoring functions to accept UniValues by value rather than by const reference ACKs for top commit: achow101: ACK d7707d9843b03f20d2a8c5a45d7b3db58e169e6f ryanofsky: Code review ACK d7707d9843b03f20d2a8c5a45d7b3db58e169e6f. No changes since last review other than rebase. I agree benchmarks showing increased peak memory usage and RSS are surprising, but number of allocations is down as expected, and runtime is also decreased. willcl-ark: ACK d7707d9843b03f20d2a8c5a45d7b3db58e169e6f Tree-SHA512: 7f511be73984553c278186286a7d161a34b2574c7f5f1a0edc87c2913b4c025a0af5241ef9af2df17547f2e4ef79710aa5bbb762fc9472435781c0488dba3435
Diffstat (limited to 'src/test')
-rw-r--r--src/test/script_tests.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index 314b26609c..39b53295e7 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -396,7 +396,7 @@ public:
wit.push_back(HexStr(scriptWitness.stack[i]));
}
wit.push_back(ValueFromAmount(nValue));
- array.push_back(wit);
+ array.push_back(std::move(wit));
}
array.push_back(FormatScript(spendTx.vin[0].scriptSig));
array.push_back(FormatScript(creditTx->vout[0].scriptPubKey));