You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge bitcoin/bitcoin#13226: Optimize SelectCoinsBnB by tracking the selection by index rather than by position
9d20052 doc: Revise comments and whitespace to clarify (Ben Woosley)
def43a4 refactor: Rename i to curr_try in SelectCoinsBnB (Ben Woosley)
1dd0923 refactor: Track BnB selection by index (Ben Woosley)
Pull request description:
This is prompted by #13167 and presented as a friendly alternative to it.
IMO you can improve code readability and performance by about 20% by tracking the selected utxos by index, rather than by position. This reduces the storage access complexity from roughly O(utxo_size) to O(selection_size).
On my machine (median of 5 trials):
```
BnBExhaustion, 5, 650, 2.2564, 0.000672999, 0.000711565, 0.000693112 - master
BnBExhaustion, 5, 650, 1.76232, 0.000528563, 0.000568806, 0.000539147 - this PR
```
ACKs for top commit:
achow101:
reACK 9d20052
glozow:
code review ACK 9d20052
Xekyo:
reACK 9d20052
Tree-SHA512: 453ea11ad58c48928dc76956e3e98916f6924e95510eb02fe89a899ff102fe9cc08a04d557f381ad0218a210275e5383101d971c1ffad38b06b1c57d81144315
if (curr_value + curr_available_value < selection_target || // Cannot possibly reach target with the amount remaining in the curr_available_value.
96
-
curr_value > selection_target + cost_of_change || // Selected value is out of range, go back and try other branch
94
+
if (curr_value + curr_available_value < selection_target || // Cannot possibly reach target with the amount remaining in the curr_available_value.
95
+
curr_value > selection_target + cost_of_change || // Selected value is out of range, go back and try other branch
97
96
(curr_waste > best_waste && (utxo_pool.at(0).fee - utxo_pool.at(0).long_term_fee) > 0)) { // Don't select things which we know will be more wasteful if the waste is increasing
98
97
backtrack = true;
99
98
} elseif (curr_value >= selection_target) { // Selected value is within range
// The previous index is included and therefore not relevant for exclusion shortcut
139
+
(utxo_pool_index - 1) == curr_selection.back() ||
140
+
// Avoid searching a branch if the previous UTXO has the same value and same waste and was excluded.
141
+
// Since the ratio of fee to long term fee is the same, we only need to check if one of those values match in order to know that the waste is the same.
0 commit comments