Reserved memory for the transaction inputs and outputs.
Split out of https://github.com/bitcoin/bitcoin/pull/30050/files#r1597631104
Reserved memory for the transaction inputs and outputs.
Split out of https://github.com/bitcoin/bitcoin/pull/30050/files#r1597631104
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For detailed information about the code coverage, see the test coverage report.
See the guideline for information on the review process.
Type | Reviewers |
---|---|
ACK | TheCharlatan, stickies-v, achow101 |
Concept ACK | josibake |
Stale ACK | theuni |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
1087@@ -1088,6 +1088,7 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
1088 coin_selection_params.tx_noinputs_size = 10 + GetSizeOfCompactSize(vecSend.size()); // bytes for output count
1089
1090 // vouts to the payees
1091+ txNew.vout.reserve(txNew.vout.size() + vecSend.size());
A few suggestions:
txNew.vout
is always empty here, so I’m not sure why we’d bother to add txNew.vout.size()
unless I’m missing something ?vecSend.size()+1
just in case.std::move
d (in both places) instead to save a copy similar to #30094?.reserve()
for the txNew.vin
as well?Hey @theuni, excellent review, thanks!
txNew.vin
, I’ve changed it to emplace_back
instead, the performance should be comparable - do you agree?1098@@ -1098,7 +1099,7 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
1099 if (IsDust(txout, wallet.chain().relayDustFee())) {
1100 return util::Error{_("Transaction amount too small")};
1101 }
1102- txNew.vout.push_back(txout);
1103+ txNew.vout.emplace_back(txout);
push_back(std::move(txout))
would be more correct (and clear).
I’ve added benchmarks to verify:
0| ns/op | op/s | err% | total | benchmark
1|--------------------:|--------------------:|--------:|----------:|:----------
2| 2,089.91 | 478,489.15 | 0.1% | 1.10 | `BenchmarkAddOutputsEmplaceBackReserve`
3| 1,257.81 | 795,031.71 | 0.1% | 1.10 | `BenchmarkAddOutputsInPlaceEmplaceBackReserve`
4| 2,594.12 | 385,487.12 | 0.2% | 1.10 | `BenchmarkAddOutputsPushBack`
5| 1,667.85 | 599,573.52 | 0.1% | 1.10 | `BenchmarkAddOutputsPushBackMoveReserve`
6| 2,089.21 | 478,649.26 | 0.1% | 1.10 | `BenchmarkAddOutputsPushBackReserve`
ended up adding it directly to txNew.vout
which is both faster and simpler - what do you think?
Concept ACK
I noticed you have benchmarks, would be nice to have the comparison of old vs new in the PR description.
Changes look good. The bench is not really useful though, because it’s testing things that aren’t in our code.
I believe @josibake was asking for a bench that demonstrates a before/after of CreateTransactionInternal
. I’m guessing that’s not really feasible though, so I think it’s enough to use your bench numbers without actually committing it.
1090@@ -1091,15 +1091,14 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
1091 txNew.vout.reserve(vecSend.size() + 1); // accommodate the possible later inserts
1092 for (const auto& recipient : vecSend)
1093 {
1094- CTxOut txout(recipient.nAmount, GetScriptForDestination(recipient.dest));
1095+ auto& txout = txNew.vout.emplace_back(recipient.nAmount, GetScriptForDestination(recipient.dest));
const auto& txout
Accommodating possible later insert as well
Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>
Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>