Skip to content

SortedBulkWrite#94

Open
l0rinc wants to merge 12 commits intobitcoin-dev-tools:masterfrom
l0rinc:detached93
Open

SortedBulkWrite#94
l0rinc wants to merge 12 commits intobitcoin-dev-tools:masterfrom
l0rinc:detached93

Conversation

@l0rinc
Copy link
Collaborator

@l0rinc l0rinc commented Jan 6, 2025

No description provided.

@github-actions
Copy link

github-actions bot commented Jan 6, 2025

📊 Benchmark results for this run (12632779781) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12632779781/index.html after the github pages "build and deployment" action has completed.

@l0rinc l0rinc changed the title -dbcache=30000 & SortedBulkWrite SortedBulkWrite Jan 8, 2025
@l0rinc l0rinc force-pushed the detached93 branch 2 times, most recently from bc5694e to e3240a1 Compare January 8, 2025 19:23
@github-actions
Copy link

github-actions bot commented Jan 8, 2025

📊 Benchmark results for this run (12677593680) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12677593680/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: 1.4%, mainnet-large: 2.1%, signet: -1.7%

@github-actions
Copy link

github-actions bot commented Jan 9, 2025

📊 Benchmark results for this run (12687333244) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12687333244/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: 0.1%, mainnet-large: 4.5%, signet: -0.8%

@github-actions
Copy link

📊 Benchmark results for this run (12697597242) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12697597242/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: 1.6%, mainnet-large: -0.2%, signet: -1.5%

@l0rinc
Copy link
Collaborator Author

l0rinc commented Jan 10, 2025

This is consistently faster, but not by much - I hope I'm doing something wrong, since this is a promising direction

@l0rinc
Copy link
Collaborator Author

l0rinc commented Jan 10, 2025

The skiplists aren't any faster when the elements are pre-sorted - seems this is a dead-end.

@l0rinc l0rinc closed this Jan 10, 2025
@l0rinc l0rinc reopened this Jan 12, 2025
@github-actions
Copy link

📊 Benchmark results for this run (12734553143) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12734553143/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: 0.9%, mainnet-large: 0.7%, signet: -1.7%

@github-actions
Copy link

📊 Benchmark results for this run (12735700559) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12735700559/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: -2.1%, mainnet-large: 3.2%, signet: 0.8%

@l0rinc
Copy link
Collaborator Author

l0rinc commented Jan 13, 2025

Wow, reversing the sorting direction seems to have a measurable effect on writing speed - especially if combined with nDefaultDbBatchSize = 64 << 20

My measurements with reindexes so far:

master (ssd):

Benchmark 1: COMMIT=35bf426e02210c1bbb04926f4ca2e0285fbfcd11 ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0
  Time (mean ± σ):     19991.811 s ± 13.229 s    [User: 38973.445 s, System: 835.037 s]
  Range (min … max):   19982.456 s … 20001.165 s    2 runs
2025-01-12T07:31:05Z [warning] Flushing large (26 GiB) UTXO set to disk, it may take several minutes
2025-01-12T07:53:51Z Shutdown: done

Flush time before: ~22 minutes and 46 seconds

nDefaultDbBatchSize = 64 << 20 + descending SortedWrite:

Benchmark 1: COMMIT=e679204139afdcef19000c398c6fd1c18c440a82 ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0
  Time (abs ≡):        18993.418 s               [User: 38371.601 s, System: 697.372 s]
2025-01-13T03:06:48Z [warning] Flushing large (26 GiB) UTXO set to disk, it may take several minutes
2025-01-13T03:14:21Z Shutdown: done

Flush time after: 7 minutes and 33 seconds


master (hdd):

Benchmark 1: COMMIT=d73f37dda221835b5109ede1b84db2dc7c4b74a1 ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -dbcache=30000 -stopatheight=878000 -reindex-chainstate -printtocon
sole=0 -connect=0
  Time (mean ± σ):     23664.320 s ± 111.385 s    [User: 35795.225 s, System: 714.912 s]
  Range (min … max):   23585.559 s … 23743.081 s    2 runs
2025-01-12T04:31:40Z [warning] Flushing large (26 GiB) UTXO set to disk, it may take several minutes
2025-01-12T05:02:39Z Shutdown: done

Flush time before: ~30 minutes and 59 seconds

nDefaultDbBatchSize = 64 << 20 + descending SortedWrite:

hyperfine --runs 1 --parameter-list COMMIT e679204139afdcef19000c398c6fd1c18c440a82 --prepare 'git checkout {COMMIT} && git clean -fxd && git reset --hard && cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_UTIL=OFF -DBUILD_TX=OFF -DBUILD_TESTS=OFF -DENABLE_WALLET=OFF -DINSTALL_MAN=OFF && cmake --build build -j$(nproc)' 'COMMIT={COMMIT} ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -dbcache=30000 -stopatheight=878000 -reindex-chainstate -printtoconsole=0 -connect=0'
Benchmark 1: COMMIT=e679204139afdcef19000c398c6fd1c18c440a82 ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -dbcache=30000 -stopatheight=878000 -reindex-chainstate -printtoconsole=0 -connect=0
  Time (abs ≡):        22328.054 s               [User: 35492.119 s, System: 609.247 s]
2025-01-13T03:56:37Z [warning] Flushing large (26 GiB) UTXO set to disk, it may take several minutes
2025-01-13T04:07:19Z Shutdown: done

Flush time after: 10 minutes and 42 seconds

@l0rinc
Copy link
Collaborator Author

l0rinc commented Jan 15, 2025

Ran a few reindexes:

hyperfine --runs 2 --parameter-list COMMIT 35bf426e02210c1bbb04926f4ca2e0285fbfcd11,256a5c04f2eb190e45ec7d7ffb058c189174780a,a5920ec25f02b8b66b6f23f00e696a86b5352d69 --prepare 'rm -f /mnt/my_storage/BitcoinData/debug.log && git checkout {COMMIT} && git clean -fxd && git reset --hard && cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_UTIL=OFF -DBUILD_TX=OFF -DBUILD_TESTS=OFF -DENABLE_WALLET=OFF -DINSTALL_MAN=OFF && cmake --build build -j$(nproc)' --cleanup 'mv /mnt/my_storage/BitcoinData/debug.log /mnt/my_storage/logs/debug-{COMMIT}.log' 'COMMIT={COMMIT} ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0'
Benchmark 1: COMMIT=35bf426e02210c1bbb04926f4ca2e0285fbfcd11 ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0
  Time (mean ± σ):     23766.362 s ±  5.864 s    [User: 36042.690 s, System: 701.176 s]
  Range (min … max):   23762.216 s … 23770.509 s    2 runs
 
Benchmark 2: COMMIT=256a5c04f2eb190e45ec7d7ffb058c189174780a ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0
  Time (mean ± σ):     22966.570 s ± 97.248 s    [User: 35741.689 s, System: 642.797 s]
  Range (min … max):   22897.805 s … 23035.335 s    2 runs
 
Benchmark 3: COMMIT=a5920ec25f02b8b66b6f23f00e696a86b5352d69 ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0
  Time (mean ± σ):     22119.481 s ± 50.626 s    [User: 35457.379 s, System: 578.014 s]
  Range (min … max):   22083.683 s … 22155.279 s    2 runs
Summary
  COMMIT=a5920ec25f02b8b66b6f23f00e696a86b5352d69 ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0 ran
    1.04 ± 0.00 times faster than COMMIT=256a5c04f2eb190e45ec7d7ffb058c189174780a ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0
    1.07 ± 0.00 times faster than COMMIT=35bf426e02210c1bbb04926f4ca2e0285fbfcd11 ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=878000 -dbcache=30000 -reindex-chainstate -connect=0
root@Ubuntu-2404-noble-amd64-base /mnt/my_storage/bitcoin # tail -3 ../logs/debug-35bf426e02210c1bbb04926f4ca2e0285fbfcd11.log 
2025-01-14T00:46:32Z Flushed fee estimates to fee_estimates.dat.
2025-01-14T00:46:32Z [warning] Flushing large (26 GiB) UTXO set to disk, it may take several minutes
2025-01-14T01:18:53Z Shutdown: done

root@Ubuntu-2404-noble-amd64-base /mnt/my_storage/bitcoin # tail -3 ../logs/debug-256a5c04f2eb190e45ec7d7ffb058c189174780a.log 
2025-01-14T13:44:14Z Flushed fee estimates to fee_estimates.dat.
2025-01-14T13:44:14Z [warning] Flushing large (26 GiB) UTXO set to disk, it may take several minutes
2025-01-14T14:06:10Z Shutdown: done

root@Ubuntu-2404-noble-amd64-base /mnt/my_storage/bitcoin # tail -3 ../logs/debug-a5920ec25f02b8b66b6f23f00e696a86b5352d69.log 
2025-01-15T02:15:48Z Flushed fee estimates to fee_estimates.dat.
2025-01-15T02:15:49Z [warning] Flushing large (26 GiB) UTXO set to disk, it may take several minutes
2025-01-15T02:24:16Z Shutdown: done

Commit 35bf426: Duration: 0:32:21
Commit 256a5c0: Duration: 0:21:56
Commit a5920ec: Duration: 0:08:27

git log --format="%h %s" 35bf426 256a5c0 a5920ec --no-walk
35bf426e02 Merge bitcoin/bitcoin#28724: wallet: Cleanup accidental encryption keys in watchonly wallets
256a5c04f2 nDefaultDbBatchSize = 64 << 20
a5920ec25f SortedWrite descending

@l0rinc l0rinc force-pushed the detached93 branch 2 times, most recently from e4ce95a to 77497f6 Compare January 15, 2025 10:00
@l0rinc
Copy link
Collaborator Author

l0rinc commented Jan 15, 2025

let's try sorting by hash only and putting erase entries to the end of the batch

@github-actions
Copy link

📊 Benchmark results for this run (12785267810) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12785267810/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: 2.0%, mainnet-large: 3.6%, signet: -0.8%

@github-actions
Copy link

📊 Benchmark results for this run (12785866983) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12785866983/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: -1.9%, mainnet-large: 1.2%, signet: -0.8%

@github-actions
Copy link

📊 Benchmark results for this run (12818682351) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12818682351/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: 4.1%, mainnet-large: 2.2%, signet: -0.0%

@l0rinc l0rinc force-pushed the detached93 branch 2 times, most recently from aa28431 to 7211cd5 Compare January 17, 2025 12:01
@github-actions
Copy link

📊 Benchmark results for this run (12828640623) will be available at: https://bitcoin-dev-tools.github.io/benchcoin/results/pr-94/12828640623/index.html after the github pages "build and deployment" action has completed.
🚀 Speedups: mainnet-default: 2.6%, mainnet-large: 1.4%, signet: 0.8%

@willcl-ark willcl-ark force-pushed the master branch 6 times, most recently from 84c2b9e to 89c44f3 Compare February 4, 2026 03:28
@willcl-ark willcl-ark force-pushed the master branch 8 times, most recently from f56ba17 to 806bf25 Compare February 11, 2026 23:00
@willcl-ark willcl-ark force-pushed the master branch 6 times, most recently from b916666 to 764baeb Compare February 19, 2026 03:33
@willcl-ark willcl-ark force-pushed the master branch 10 times, most recently from 26c3f30 to ae11e54 Compare February 26, 2026 03:29
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.

2 participants