Page MenuHomePhabricator

Reduce memory allocations in getblocktemplate
ClosedPublic

Authored by jasonbcox on May 13 2020, 23:14.

Details

Summary

Utilize the new reserve() function in UniValue
in order to not reallocate the transactions vector when
capacity increases.

Also utilize __pushKV which does not check for duplicate keys.

This improves getblocktemplate performance by ~4% on my machine.

I only touched the tx loop since it's the most performance-critical
section of this code, especially as the number of txs increases.

Depends on D6063

Test Plan
ninja check check-functional

Setup:

bitcoind -connect=0 -port=9999 -rpcport=9998 -datadir=/temp -prune=1000 -listen=1    # dummy node so gbt works
bitcoind -connect=0 -addnode=127.0.0.1:9999
bitcoin-cli invalidateblock <hash from a few blocks back>
bitcoin-cli getmempoolinfo    # verify number of txs is in the thousands

Run on D6063 and this patch and compare timing result:

{ for X in {1..200} ; do time ./src/bitcoin-cli getblocktemplate ; done ; } 2>&1 > /dev/null | grep real | grep -o "[0-9]\.[0-9]*" | awk '{total+=$1; count+=1} END {print total/count}'

Event Timeline

This revision is now accepted and ready to land.May 14 2020, 00:44