Decouples part of #26966.
Right now, index initial sync writes to disk for every block, which is not the best for HDD. This change batches those, so disk writes are less frequent during initial sync. This also cuts down cs_main contention by reducing the number of NextBlockSync calls (instead of calling it for every block, we will call it once per block window), making the node more responsive (IBD and validation) while indexes sync up. On top of that, it lays the groundwork for the bigger speedups, since part of the parallelization pre-work is already in place.
Just as a small summary:
- Batch DB writes instead of flushing per block, which improves sync time on HDD due to the reduced number of disk write operations.
- Reduce
cs_mainlock contention, which improves the overall node responsiveness (and primarily IBD) while the indexes threads are syncing. - Lays the groundwork for the real speedups, since part of #26966 parallelization pre-work is introduced here as well.
Note: Pending initial sync benchmark and further testing. I have only focused on decoupling and simplifying what was in #26966 first. Commits should be simple to diggest.