Skip to content

Batch RocksDB writes in snapcake for improved I/O performance#101

Merged
liuchengxu merged 5 commits intomainfrom
snapcake-batch-rocksdb-writes
Jan 3, 2026
Merged

Batch RocksDB writes in snapcake for improved I/O performance#101
liuchengxu merged 5 commits intomainfrom
snapcake-batch-rocksdb-writes

Conversation

@liuchengxu
Copy link
Copy Markdown
Member

Summary

  • Replace per-UTXO RocksDB writes with batch writes using rocksdb::WriteBatch
  • Collect all UTXOs from each state response into a pre-allocated Vec, then write atomically
  • Reduces disk operations from ~360M+ to ~18K for mainnet (~10,000-20,000x fewer operations)

Test plan

  • Run snapcake against a Subcoin node and verify snapshot generation completes successfully
  • Verify generated snapshot checksum matches expected value

Instead of writing each UTXO individually to RocksDB (2-3 operations
per UTXO), collect all UTXOs from a state response and write them
in a single atomic batch using rocksdb::WriteBatch.

This reduces disk operations from ~360M+ to ~18K for mainnet,
providing 10,000-20,000x fewer disk operations.

Changes:
- Replace push()/store_utxo() with push_batch()/store_utxos_batch()
- Use rocksdb::WriteBatch for atomic batch writes
- Pre-allocate Vec based on response entry count
- Fix typo: key_vlaue_state_entry → key_value_state_entry
- Extract magic number 6 to CONFIRMATION_DEPTH constant
- Replace abrupt std::process::exit(0) with shutdown channel signal
  for cleaner separation of concerns
By default, mDNS and local peer discovery are disabled in snapcake.
This adds a --discover-local flag that enables mDNS-based discovery
for development and testing scenarios with multiple nodes on the
same local network.
Group snapcake-specific parameters into SnapcakeSyncParams struct
to reduce function arguments from 8 to 4.
@liuchengxu liuchengxu merged commit 4963a55 into main Jan 3, 2026
5 checks passed
@liuchengxu liuchengxu deleted the snapcake-batch-rocksdb-writes branch January 3, 2026 15:16
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.

1 participant