bench: Utilitze setup() in WalletBalance for marking caches dirty
What changed, and why it matters
This is a benchmark-only change. It moves a 'mark cache dirty' step out of the timed portion of a wallet balance performance test so the benchmark measures only the balance calculation itself. There is no change to production wallet code, consensus logic, networking, or any user-facing behavior.
No security action needed. Treat as normal code-quality/test refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors src/bench/wallet_balance.cpp to use nanobench’s setup() hook for wallet.MarkDirty() instead of running it inside bench.run(). It also replaces a one-sided assertion (add_mine implies bal.m_mine_trusted > 0) with an exact equivalence check and adds doNotOptimizeAway(bal). The actual GetBalance implementation and wallet state handling are untouched.
Changed components
src/bench/wallet_balance.cppInspect captured patch +8 / −5
diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp
index d9cd4bbb..07fd46a9 100644
--- a/src/bench/wallet_balance.cpp
+++ b/src/bench/wallet_balance.cpp
@@ -53,11 +53,14 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
auto bal = GetBalance(wallet); // Cache
- bench.run([&] {
- if (set_dirty) wallet.MarkDirty();
- bal = GetBalance(wallet);
- if (add_mine) assert(bal.m_mine_trusted > 0);
- });
+ bench.setup([&] {
+ if (set_dirty) wallet.MarkDirty();
+ })
+ .run([&] {
+ bal = GetBalance(wallet);
+ ankerl::nanobench::doNotOptimizeAway(bal);
+ assert(add_mine == (bal.m_mine_trusted > 0));
+ });
}
static void WalletBalanceDirty(benchmark::Bench& bench) { WalletBalance(bench, /*set_dirty=*/true, /*add_mine=*/true); }
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.