btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.11k stars 2.32k forks source link

blockchain: Use slices when fetching utxos #1972

Closed kcalvinalvin closed 1 year ago

kcalvinalvin commented 1 year ago

Maps have a higher overhead than slices. As slices can be used instead of maps, we avoid the overhead of making a map.

This was one of the overheads I've noticed when profiling ibd for PR #1955

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 4894156905


Changes Missing Coverage Covered Lines Changed/Added Lines %
blockchain/utxoviewpoint.go 13 21 61.9%
<!-- Total: 17 25 68.0% -->
Files with Coverage Reduction New Missed Lines %
peer/peer.go 4 73.2%
<!-- Total: 4 -->
Totals Coverage Status
Change from base Build 4755006470: -0.009%
Covered Lines: 26649
Relevant Lines: 48220

💛 - Coveralls
kcalvinalvin commented 1 year ago

Addressed the reviews in the latest push

kcalvinalvin commented 1 year ago

Pushed an extra commit with benchmarks.

I'm seeing a ~25% performance improvement.

[N] calvin@bitcoin ~/b/g/u/g/s/g/b/b/blockchain (utxoview-use-slices)> go test -run=XXX -bench=BenchmarkUtxo
goos: linux
goarch: amd64
pkg: github.com/btcsuite/btcd/blockchain
cpu: AMD Ryzen 5 3600 6-Core Processor              
BenchmarkUtxoFetchMap-10        17066674                71.06 ns/op
BenchmarkUtxoFetchSlices-10     19618462                52.60 ns/op
PASS
ok      github.com/btcsuite/btcd/blockchain     2.384s