bench: add benchmark for wallet 'AvailableCoins' function. #25234

pull furszy wants to merge 1 commits into bitcoin:master from furszy:2022_bench_wallet_available_coins changing 1 files +40 −0
  1. furszy commented at 2:19 PM on May 28, 2022: member

    Rationale

    AvailableCoins is part of several important flows for the wallet; from RPC commands that create transactions like fundrawtransaction, send, walletcreatefundedpsbt, get the available balance, list the available coins with listunspent etc. to GUI connected processes that perform the same or similar actions: tx creation, available balance calculation, present the spendable coins in the coin control dialog.

    As we are improving this process in #24699, #25005 and there are more structural changes coming on the way. This benchmark aims to ensure us that, at least, there are no regressions (obviously performance improvements are great but, at least for me, this heads into the direction of having a base metric to compare future structural changes).

    Implementation Notes

    There are 5 new benchmarks, one per wallet supported output type (LEGACY, P2SH_SEGWIT, BECH32, BECH32M), plus a multi-output-type wallet benchmark which contains outputs from all the descriptor types.

    The test, by default, fills-up the wallet with 1k transactions, 2k outputs. Mainly to not consume much time if the user just want to verify that no substantial regressions were introduced. But, my expectation for those who are focused on this process is to use a much higher number locally to really note the differences across commits.

  2. DrahtBot commented at 3:08 PM on May 28, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK achow101, hernanmarino, aureleoules
    Concept ACK laanwj, pablomartin4btc

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label Build system on May 28, 2022
  4. laanwj added the label Wallet on Jun 1, 2022
  5. laanwj added the label Tests on Jun 1, 2022
  6. laanwj removed the label Build system on Jun 1, 2022
  7. in src/test/util/wallet.cpp:26 in ca8ef4c6f7 outdated
      19 | @@ -20,11 +20,15 @@ const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqq
      20 |  std::string getnewaddress(CWallet& w)
      21 |  {
      22 |      constexpr auto output_type = OutputType::BECH32;
      23 | +    return EncodeDestination(getnewaddress(w, output_type));
      24 | +}
      25 | +
      26 | +CTxDestination getnewaddress(CWallet& w, OutputType output_type)
    


    laanwj commented at 8:30 PM on June 1, 2022:

    Please give this function a different name, overloading it based on return type and an extra parameter can be potentially confusing.


    furszy commented at 12:07 PM on June 2, 2022:

    yeah agree, pushed.

  8. laanwj commented at 8:59 PM on June 1, 2022: member

    Concept ACK on benchmarking these, however there have been recent complaints that the benchmarks are slow, and I've noticed these add more fairly slow to run benchmarks:

    |               ns/op |                op/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |      359,740,298.60 |                2.78 |    0.0% |     19.79 | `WalletAvailableCoinsMulti`
    |      289,759,212.20 |                3.45 |    0.0% |     15.93 | `WalletAvailableCoinsOnlyBech32`
    |      559,973,432.00 |                1.79 |    0.0% |     30.80 | `WalletAvailableCoinsOnlyBech32M`
    |      196,348,457.20 |                5.09 |    0.0% |     10.80 | `WalletAvailableCoinsOnlyLegacy`
    |      304,247,935.40 |                3.29 |    0.0% |     16.73 | `WalletAvailableCoinsOnlyP2SH_SEGWIT`
    

    E.g. a total of 94 seconds to the runtime of bench_bitcoin with default settings.

  9. furszy commented at 12:13 PM on June 2, 2022: member

    Thanks laanwj for the review!

    It's interesting to see other results, locally this are my results:

    |               ns/op |                op/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |      132,289,908.40 |                7.56 |    0.3% |      7.27 | `WalletAvailableCoinsMulti`
    |      104,691,758.40 |                9.55 |    0.1% |      5.77 | `WalletAvailableCoinsOnlyBech32`
    |      196,688,875.00 |                5.08 |    0.2% |     10.82 | `WalletAvailableCoinsOnlyBech32M`
    |       70,386,791.80 |               14.21 |    0.2% |      3.88 | `WalletAvailableCoinsOnlyLegacy`
    |      111,477,558.20 |                8.97 |    0.1% |      6.14 | `WalletAvailableCoinsOnlyP2SH_SEGWIT`
    

    But let me do something, going to decrease the bench number of iterations from 5 to 2. It should decrease the total time by half.

  10. furszy force-pushed on Jun 2, 2022
  11. furszy commented at 12:24 PM on June 2, 2022: member

    Done, decreased the number of iterations to 2. And this are the results:

    |               ns/op |                op/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |      129,406,083.50 |                7.73 |    0.0% |      2.85 | `WalletAvailableCoinsMulti`
    |      105,704,646.00 |                9.46 |    0.2% |      2.33 | `WalletAvailableCoinsOnlyBech32`
    |      206,642,667.00 |                4.84 |    0.6% |      4.55 | `WalletAvailableCoinsOnlyBech32M`
    |       69,838,895.50 |               14.32 |    0.0% |      1.54 | `WalletAvailableCoinsOnlyLegacy`
    |      112,263,500.00 |                8.91 |    0.0% |      2.47 | `WalletAvailableCoinsOnlyP2SH_SEGWIT`
    

    Total time: ~15 seconds to run the 5 new benchmarks at most here now. Previously, with 5 iterations, total time was ~40 seconds. So, you should see more or less a 40% total time decrease there as well.

  12. furszy commented at 12:44 PM on June 2, 2022: member

    Aside from that, I think that a good future question to ask ourselves would be whether we want to always run all the benchmarks all the time or not. Because, sooner or later, as the project isn't going to stop growing, we could end up sacrificing accuracy, implementing not entirely real scenarios (skipping parts of the flow that is being benchmarked) in favor of decreasing the total bench time (there is where my comment in #24924#pullrequestreview-985000006 heads to for example).

    But well, this is just me thinking out loud.. after #24924, the total bench time will be pretty decent to not have to worry about this for a while.

  13. in src/bench/wallet_available_coins.cpp:86 in 4029293e8c outdated
      81 | +            wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
      82 | +            wallet.SetupDescriptorScriptPubKeyMans();
      83 | +        }
      84 | +        if (std::any_of(output_type.begin(), output_type.end(), [](OutputType type){return type == OutputType::LEGACY;})) {
      85 | +            wallet.SetupLegacyScriptPubKeyMan();
      86 | +        }
    


    achow101 commented at 6:43 PM on June 2, 2022:

    In b791c2ae2eb02ff53762ac5ed2b355e5248ac041 "bench: add benchmark for wallet 'AvailableCoins' function."

    The type of ScriptPubKeyMan is not related to the OutputType, so having this depend on the OutputType does not make sense. Unfortunately the word "legacy" refers to a number of different things within the wallet.

    The type of wallet is only going to have an effect on how IsMine performs, and I don't think that really matters for this measurement.

  14. in src/bench/wallet_available_coins.cpp:127 in 4029293e8c outdated
     123 | +
     124 | +BENCHMARK(WalletAvailableCoinsOnlyBech32M);
     125 | +BENCHMARK(WalletAvailableCoinsOnlyBech32);
     126 | +BENCHMARK(WalletAvailableCoinsOnlyP2SH_SEGWIT);
     127 | +BENCHMARK(WalletAvailableCoinsOnlyLegacy);
     128 | +BENCHMARK(WalletAvailableCoinsMulti);
    


    achow101 commented at 6:46 PM on June 2, 2022:

    In b791c2ae2eb02ff53762ac5ed2b355e5248ac041 "bench: add benchmark for wallet 'AvailableCoins' function."

    I don't really think it is useful to have AvailableCoins run for different OutputTypes. There really isn't any difference for how AvailableCoins behaves depending on the OutputType.


    furszy commented at 10:36 PM on June 26, 2022:

    Hmm, wouldn't we be having the same benchmark times for all the cases if that would be the case? (we are adding the same amount of txs and outputs to each of them).

    I mean, your #24699 improves exactly this. The time difference there is for the solving provider and IsMine related calls.


    achow101 commented at 3:16 PM on July 6, 2022:

    Yes, it should be the same benchmark times for all cases, so it doesn't make sense to run it separately for each OutputType.

  15. furszy force-pushed on Jun 26, 2022
  16. DrahtBot added the label Needs rebase on Jul 12, 2022
  17. furszy commented at 2:01 PM on August 31, 2022: member

    Note: haven't updated this PR because a similar benchmark is introduced in #25685.

    So, once/if that one gets merged, will rebase this work on top. The amount of changes here will be pretty small.

  18. hernanmarino commented at 2:43 PM on November 8, 2022: contributor

    Approach ACK fd583c8184ef2a270e7df13360f78fd9dda258a0. @furszy are you planning on rebasing this one, now that #25685 was merged ?

  19. pablomartin4btc commented at 2:53 PM on November 8, 2022: member

    Aside from that, I think that a good future question to ask ourselves would be whether we want to always run all the benchmarks all the time or not. Because, sooner or later, as the project isn't going to stop growing, we could end up sacrificing accuracy, implementing not entirely real scenarios...

    I can see you also introduced that idea and the improvement is already merged and available; good stuff!

  20. pablomartin4btc commented at 2:58 PM on November 8, 2022: member

    Code review ACK. I've verified most changes were already merged on #25685, waiting for your next commit to re ACK this PR again.

  21. furszy commented at 9:50 PM on November 8, 2022: member

    yeah, will rebase + rearrange it in the coming days. Thanks for the ping 👍🏼 .

  22. furszy force-pushed on Nov 14, 2022
  23. DrahtBot removed the label Needs rebase on Nov 14, 2022
  24. bench: add benchmark for wallet 'AvailableCoins' function. 3a4f8bc242
  25. in src/bench/wallet_create_tx.cpp:168 in b2ec705072 outdated
     163 | +    assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
     164 | +
     165 | +    bench.epochIterations(2).run([&] {
     166 | +        LOCK(wallet.cs_wallet);
     167 | +        const auto& res = wallet::AvailableCoins(wallet);
     168 | +        std::cout << res.All().size() << std::endl;
    


    achow101 commented at 4:43 PM on December 15, 2022:

    I think this is a debugging leftover?


    furszy commented at 6:44 PM on December 15, 2022:

    it's all about perspective, could be a feature too.

    fixed, thanks.

  26. furszy force-pushed on Dec 15, 2022
  27. achow101 commented at 8:47 PM on December 15, 2022: member

    ACK 3a4f8bc24271d05765e9bf1e26558a28ab2e6b81

  28. furszy requested review from pablomartin4btc on Dec 19, 2022
  29. furszy removed review request from pablomartin4btc on Dec 19, 2022
  30. furszy requested review from hernanmarino on Dec 19, 2022
  31. furszy removed review request from hernanmarino on Dec 19, 2022
  32. furszy requested review from pablomartin4btc on Dec 19, 2022
  33. hernanmarino commented at 2:49 PM on December 22, 2022: contributor

    ACK 3a4f8bc24271d05765e9bf1e26558a28ab2e6b81

  34. hernanmarino approved
  35. hernanmarino commented at 2:53 PM on December 22, 2022: contributor

    This is my output :

    |               ns/op |                op/s |    err% |          ins/op |         bra/op |   miss% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------------:|---------------:|--------:|----------:|:----------
    |       10,914,205.50 |               91.62 |    0.1% |  136,775,849.50 |  12,819,423.00 |    0.0% |      0.24 | `WalletAvailableCoins`
    
    
  36. pablomartin4btc commented at 7:10 PM on December 22, 2022: member

    tested ACK.

    Here my results:

    |--------------------:|--------------------:|--------:|----------:|:----------
    |       20,730,690.00 |               48.24 |    3.8% |      0.47 | `WalletAvailableCoins`
    

    From time to time I get recommendations to increase the iters as it warns unstability:

    |--------------------:|--------------------:|--------:|----------:|:----------
    |       20,150,356.50 |               49.63 |    5.3% |      0.48 | :wavy_dash: `WalletAvailableCoins` (Unstable with ~2.0 iters. Increase `minEpochIterations` to e.g. 20)
    

    Not sure if this could be an issue.

  37. in src/bench/wallet_create_tx.cpp:182 in 3a4f8bc242
     177 |  
     178 | +static void WalletAvailableCoins(benchmark::Bench& bench) { AvailableCoins(bench, {OutputType::BECH32M}); }
     179 | +
     180 |  BENCHMARK(WalletCreateTxUseOnlyPresetInputs, benchmark::PriorityLevel::LOW)
     181 |  BENCHMARK(WalletCreateTxUsePresetInputsAndCoinSelection, benchmark::PriorityLevel::LOW)
     182 | +BENCHMARK(WalletAvailableCoins, benchmark::PriorityLevel::LOW);
    


    aureleoules commented at 2:52 PM on December 28, 2022:

    nit: missing new line

  38. aureleoules approved
  39. aureleoules commented at 3:50 PM on December 28, 2022: member

    ACK 3a4f8bc24271d05765e9bf1e26558a28ab2e6b81

  40. achow101 merged this on Jan 4, 2023
  41. achow101 closed this on Jan 4, 2023

  42. sidhujag referenced this in commit b23c80f51c on Jan 4, 2023
  43. furszy deleted the branch on May 27, 2023
  44. bitcoin locked this on May 26, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 00:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me