Problem: Block-index ordering is used by chain selection and CheckBlockIndex().
The work comparator makes repeated out-of-line comparisons of chain work, sequence IDs, and addresses.
CheckBlockIndex() is enabled by default on regtest, including functional tests, but disabled by default on mainnet.
Fix: Inline the block-index comparators, compare the work-ordering key with std::tie, and use one three-way comparison per 32-bit word in arith_uint256.
Ordering is unchanged. Fixed-order unit tests pin the expected results, and two differential fuzz targets compare against the original implementations.
Measurement: Earlier GCC 15.0.1 and Clang 22.0.0 runs reported the following base-to-final improvements on the older stack. These are historical measurements, not fresh measurements of the current head.
| Compiler | Synthetic 256-bit work comparisons | CheckBlockIndex |
|---|---|---|
| GCC 15.0.1 | 6.51× | 1.62× |
| Clang 22.0.0 | 6.80× | 1.39× |
The current benchmark also covers 12-bit and 96-bit work values.
<details> <summary>Measure the current comparison workloads</summary>
cmake -B build -DBUILD_BENCH=ON -DCMAKE_BUILD_TYPE=Release &&
cmake --build build -j10 --target bench_bitcoin &&
build/bin/bench_bitcoin -filter='CBlockIndexWorkComparator.*|CheckBlockIndex' -min-time=5000
Compare before and after builds with the same compiler and configuration. The quoted historical runs used benchmark commit b60450fae8 and final commit deb58eea2f.
</details>