Optimize indexer package #219
Labels
help wanted
Extra attention is needed
optimization
An opportunity for a performance boost
refactoring
Some refactoring is needed
The indexer package is extremely inefficient and is responsible for most of the time spent syncing the chain.
Benchmarks show that around 90-95% of the time syncing the chain is due to two processes ― loading the utxos from disk to validate them, and running the indexer.
Of those two the indexer takes about twice the amount of time as loading the utxos. And the utxo cost can potentially be dramatically reduced by setting
--utxocachemaxsize
to hold the entire utxo set in memory.This would leave about 90% of the sync time exclusively due to the indexer (which you obviously wouldn't pay if you turn off all indexes).
Refactoring this will take some clever engineering. Right now blocks are passed in to the indexer as they are processed (and in the same db transaction). This guarantees that the indexer tracks the tip of the chain and is always caught up with the best chain.
It seems like an optimization might be to have the indexer have access to the block index and use the index in separate goroutines to load blocks and index them. However, the challenge is this might be even slower if it needs to load blocks from disk rather than having them passed in from memory. But the separate goroutine approach may allow each indexer to be run in parallel rather than serially.
If you're a strong Go dev who would like to tackle this optimization it would be greatly appreciated.
The text was updated successfully, but these errors were encountered: