TxWriter is surprizingly slow considering what it does is very simple, however, the bottleneck is LookupIndex, which in insert_pairs reads from the DB before updating, which is very slow.
Instead, use merge_cf like in D14430, which avoids that roundrip, and RocksDB is able to combine a read+write efficiently for us.
To resync the first 300000-ish blocks, with all other indices disabled (i.e. only TxWriter), we get an overall speedup of almost 2x. Note that this still includes reading the blocks from disk etc., which seems to have an overhead of 821.10s (see D15552, where one benchmark strips basically everything away), so factoring this out we get a speedup of roughly 4x.
The insert call itself is now extremely fast, because it basically just issues a bunch of merge_cf calls, and the real action is handled by RocksDB, so benchmarking the call isn't too useful anymore.
bench | total time [s] | time TxWriter::insert [s] |
master | 2378.86 | 1134.73 |
merge_cf | 1212.08 | 36.9 |
Depends on D15547