Skip to content

IBD: Batch UTXO set writes#882

Open
RossKU wants to merge 3 commits intokaspanet:masterfrom
RossKU:batch-utxo-writes-768
Open

IBD: Batch UTXO set writes#882
RossKU wants to merge 3 commits intokaspanet:masterfrom
RossKU:batch-utxo-writes-768

Conversation

@RossKU
Copy link

@RossKU RossKU commented Feb 23, 2026

Replace DirectDbWriter with WriteBatch/BatchDbWriter in IBD and pruning UTXO write paths (write_many, write_from_iterator_without_cache, write_diff). Also adds write_many_without_cache for the IBD import path where cache population is unnecessary.

Closes #768

Convert all DirectDbWriter usage in utxo_set.rs to BatchDbWriter:
- write_many: use WriteBatch for batched DB writes
- write_diff: reuse existing write_diff_batch
- write_from_iterator_without_cache: use WriteBatch
- Add write_many_without_cache for IBD (batch + skip cache)

Closes kaspanet#768
During IBD, UTXO chunks imported from peers do not benefit from
caching. Switch to write_many_without_cache which uses BatchDbWriter
and skips cache population.
UtxoSetStore trait is no longer needed since write_many_without_cache
is a direct method on DbUtxoSetStore, not a trait method.
@freshair18
Copy link
Collaborator

Did you run practical tests regarding the effect of this? can you share the results?

@freshair18
Copy link
Collaborator

@freshair18
Copy link
Collaborator

freshair18 commented Feb 23, 2026

I think #850 also revolves around the same aspects.
Probably a good time to review and incorporate these PRs.

@RossKU
Copy link
Author

RossKU commented Feb 23, 2026

I interpreted "the effect of this" as the performance difference between DirectDbWriter (one db.put() per
entry) and BatchDbWriter (all writes collected into a WriteBatch, then flushed in a single db.write()
call), so I ran a criterion benchmark comparing the two approaches with chunk sizes representative of the IBD
UTXO import path.

Results (Windows 11, release build):

Chunk size DirectDbWriter (old) BatchDbWriter (new) Speedup
1,000 UTXOs 11.64 ms 7.23 ms ~1.6x
10,000 UTXOs 56.75 ms 14.20 ms ~4.0x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IBD: Batch UTXO set writes

2 participants