#34360 bench: add WalletBalanceManySpent for high-history wallet scenario

full analysis

https://github.com/bitcoin/bitcoin/pull/34360 · w0xlt · +237/-64 in 3 files, 2 commits · labels: Tests, Needs rebase, CI failed · draft

Goal

  • Benchmark wallet balance calculation performance on wallets with heavy spent output histories
  • Help developers profile and measure optimizations for high-activity wallets like Lightning nodes

This pull request adds the `WalletBalanceManySpent` benchmark to measure `GetBalance()` performance on wallets with large transaction histories consisting mostly of spent outputs. It also refactors `GenerateFakeBlock` into a shared utility header to avoid duplicated setup logic across wallet benchmarks.

Problem: Wallets with extensive history, such as Lightning routing nodes or exchange hot wallets, face slow balance calculations because spent outputs are repeatedly scanned. Developers lacked a dedicated benchmark to profile and measure optimizations for this scenario.

Category: Test infrastructure (#26 of 45)

P3 · test coverage

  • P3 because it adds dedicated benchmark coverage to profile balance calculation under heavy output load
  • Helps quantify performance improvements for high-activity wallet use cases without touching production code

P3 because it adds valuable test infrastructure to profile wallet balance calculations under heavy output loads. Author w0xlt notes it was specifically created to evaluate #27865, demonstrating a 2,981x speedup when separating spent TXOs. It adds benchmark coverage for high-activity wallet use cases without modifying production code.

Membership: Adds a new benchmark harness to src/bench/ and refactors shared wallet benchmark utility helpers.

Factors: security/stability 0, bug 0, performance 0, user value 1, leverage 1

Reviewability: Stale: Needs rebase

  • Review is blocked by merge conflicts and failing CI

The pull request is in a dirty mergeable state with open merge conflicts and a failing CI pipeline.

Author status: active, last rebased in August 2026 after review comments were addressed

Resolved concerns:

  • l0rinc requested multiple refactorings including parameter naming, deduplicating constants, avoiding redundant vector copies, cleaner block tip handling, and extracting fake block generation into a shared helper; w0xlt implemented these and gave co-author credit.

Agreement: Strong

  • Strong support with no open objections after review suggestions were addressed
  • Formal approval after collaborative refactoring of benchmark utilities (l0rinc)
  • Noted as relevant to evaluating wallet balance improvements in #27865 (fanquake)

Strong: l0rinc ACKed after all review suggestions were implemented, with no objections raised.

l0rinc conducted an extensive review, collaborated on refactoring the benchmark utilities, and formally ACKed the revised implementation.

  • l0rinc ACKed commit 5defb96 after suggestions were incorporated
  • fanquake cc'd achow101 noting relevance to #27865
  • sedited pinged for rebases

Review verdicts (DrahtBot): 0 (+1)

Dependencies

Enables:

Files

File list not available for this run.

Card

This PR adds the WalletBalanceManySpent benchmark to measure GetBalance() performance when a wallet contains tens of thousands of spent outputs and relatively few unspent coins, simulating high-activity wallets like exchange hot wallets or Lightning nodes. It also extracts fake block generation helpers into a shared benchmark header. It was built to evaluate PR 27865, where it demonstrated a massive speedup in balance calculation. The PR has strong review support with an ACK from l0rinc, but is currently marked draft and blocked by merge conflicts and failing CI.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T15:50, confidence high, input hash ad72125758f4af67