[Chronik] Optimize prepare_indexed_txs by using batch queries and removing redundancy
Summary:
Currently, prepare_indexed_txs is doubly inefficient:
- If two inputs spend two outputs from the same tx, it'll query the tx num of this tx twice
- It queries tx nums one-by-one, instead of utilizing the optimized batch query gets that RocksDB provides
We fix this by adding batch query versions to LookupColumn and TxReader, and then utilize those in prepare_indexed_txs.
Note: We can't use sorted_inputs anywhere in this function when querying input_tx_nums, since those can come in a random order.
Benchmarks show there's a speedup of about 1.6 when syncing the first 300000ish blocks:
bench | total time [s] | time prepare [s] |
no prepare | 1066.85 | 0 |
master | 4375.39 | 3308.54 |
this diff | 3148.51 | 2081.66 |
Test Plan: ninja check-crates && ninja check-functional
Reviewers: Fabien, #bitcoin_abc
Reviewed By: Fabien, #bitcoin_abc
Differential Revision: https://reviews.bitcoinabc.org/D15571