HomePhabricator

Reduce memory allocations in getblocktemplate

Description

Reduce memory allocations in getblocktemplate

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}'

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6065

Details

Provenance
jasonbcoxAuthored on May 13 2020, 23:03
abc-botPushed on May 14 2020, 01:40
Reviewer
Restricted Project
Differential Revision
D6065: Reduce memory allocations in getblocktemplate
Parents
rSTAGING3e4f45f38e83: Fix string layout in rpc/rawtransaction.cpp
Branches
Unknown
Tags
Unknown