HomePhabricator

[Chronik] Optimize `prepare_indexed_txs` by using batch queries and removing…

Description

[Chronik] Optimize prepare_indexed_txs by using batch queries and removing redundancy

Summary:
Currently, prepare_indexed_txs is doubly inefficient:

  1. If two inputs spend two outputs from the same tx, it'll query the tx num of this tx twice
  2. 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:

benchtotal time [s]time prepare [s]
no prepare1066.850
master4375.393308.54
this diff3148.512081.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

Details

Provenance
tobias_ruckAuthored on Feb 28 2024, 11:36
tobias_ruckPushed on Feb 29 2024, 11:17
Reviewer
Restricted Project
Differential Revision
D15571: [Chronik] Optimize `prepare_indexed_txs` by using batch queries and removing redundancy
Parents
rABCdde125e4a200: [guix] build chronik on Windows
Branches
Unknown
Tags
Unknown