aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2022-04-19 10:16:54 +0200
committerMarcoFalke <falke.marco@gmail.com>2022-04-19 10:17:26 +0200
commit907659770bd2e95f4f4af652eb9e443772f2c0f1 (patch)
tree44c952d1bbe0442e3809f1cb253d66f7097eb2ae
parent57a73d71a36ce212977607d3e94de6ef55521bfc (diff)
parent464a16281791ee89be0072c230f07d4496021f15 (diff)
downloadbitcoin-907659770bd2e95f4f4af652eb9e443772f2c0f1.tar.xz
Merge bitcoin/bitcoin#24913: bench: Add a benchmark for wallet loading
464a16281791ee89be0072c230f07d4496021f15 bench: Add a benchmark for wallet loading (Andrew Chow) Pull request description: I've been working on some improvements to wallet loading performance and it's useful to have a benchmark to check whether these improvements are actually improvements. ACKs for top commit: w0xlt: ACK 464a162 jarolrod: Code Review ACK https://github.com/bitcoin/bitcoin/commit/464a16281791ee89be0072c230f07d4496021f15 Tree-SHA512: 0a68166ee1c43c88a22688c91c0a1949b7ab81373e3466c8ee85d09c7841fd033dcbcb7fb4a05e9824635f1f9065ab091b5a413e08d51ae58e2ed5fe24ea2e3f
-rw-r--r--src/Makefile.bench.include1
-rw-r--r--src/bench/wallet_loading.cpp83
2 files changed, 84 insertions, 0 deletions
diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include
index 5dae4374e3..58a09cd4a4 100644
--- a/src/Makefile.bench.include
+++ b/src/Makefile.bench.include
@@ -74,6 +74,7 @@ endif
if ENABLE_WALLET
bench_bench_bitcoin_SOURCES += bench/coin_selection.cpp
bench_bench_bitcoin_SOURCES += bench/wallet_balance.cpp
+bench_bench_bitcoin_SOURCES += bench/wallet_loading.cpp
endif
bench_bench_bitcoin_LDADD += $(BDB_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS)
diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp
new file mode 100644
index 0000000000..38d3460001
--- /dev/null
+++ b/src/bench/wallet_loading.cpp
@@ -0,0 +1,83 @@
+// Copyright (c) 2022 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <bench/bench.h>
+#include <interfaces/chain.h>
+#include <node/context.h>
+#include <test/util/mining.h>
+#include <test/util/setup_common.h>
+#include <test/util/wallet.h>
+#include <util/translation.h>
+#include <validationinterface.h>
+#include <wallet/context.h>
+#include <wallet/receive.h>
+#include <wallet/wallet.h>
+
+#include <optional>
+
+using wallet::CWallet;
+using wallet::DatabaseOptions;
+using wallet::DatabaseStatus;
+using wallet::ISMINE_SPENDABLE;
+using wallet::MakeWalletDatabase;
+using wallet::WALLET_FLAG_DESCRIPTORS;
+using wallet::WalletContext;
+
+static const std::shared_ptr<CWallet> BenchLoadWallet(WalletContext& context, DatabaseOptions& options)
+{
+ DatabaseStatus status;
+ bilingual_str error;
+ std::vector<bilingual_str> warnings;
+ auto database = MakeWalletDatabase("", options, status, error);
+ assert(database);
+ auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings);
+ NotifyWalletLoaded(context, wallet);
+ if (context.chain) {
+ wallet->postInitProcess();
+ }
+ return wallet;
+}
+
+static void BenchUnloadWallet(std::shared_ptr<CWallet>&& wallet)
+{
+ SyncWithValidationInterfaceQueue();
+ wallet->m_chain_notifications_handler.reset();
+ UnloadWallet(std::move(wallet));
+}
+
+static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
+{
+ const auto test_setup = MakeNoLogFileContext<TestingSetup>();
+
+ WalletContext context;
+ context.args = &test_setup->m_args;
+ context.chain = test_setup->m_node.chain.get();
+
+ // Setup the wallet
+ // Loading the wallet will also create it
+ DatabaseOptions options;
+ if (!legacy_wallet) options.create_flags = WALLET_FLAG_DESCRIPTORS;
+ auto wallet = BenchLoadWallet(context, options);
+
+ // Generate a bunch of transactions and addresses to put into the wallet
+ for (int i = 0; i < 5000; ++i) {
+ generatetoaddress(test_setup->m_node, getnewaddress(*wallet));
+ }
+
+ // reload the wallet for the actual benchmark
+ BenchUnloadWallet(std::move(wallet));
+
+ bench.minEpochIterations(10).run([&] {
+ wallet = BenchLoadWallet(context, options);
+
+ // Cleanup
+ BenchUnloadWallet(std::move(wallet));
+ });
+}
+
+static void WalletLoadingLegacy(benchmark::Bench& bench) { WalletLoading(bench, /*legacy_wallet=*/true); }
+static void WalletLoadingDescriptors(benchmark::Bench& bench) { WalletLoading(bench, /*legacy_wallet=*/false); }
+
+BENCHMARK(WalletLoadingLegacy);
+BENCHMARK(WalletLoadingDescriptors);