HomePhabricator

Merge #14984: rpc: Speedup getrawmempool when verbose=true

Description

Merge #14984: rpc: Speedup getrawmempool when verbose=true

Summary:
2d5cf4c41d rpc: Speedup getrawmempool when verbose=true (João Barbosa)

Pull request description:

Instead of calling `pushKV(hash, info)`, which incurs in duplicate key checks, call `__pushKV` which (currently) doesn't.

Improves RPC `getrawmempool` and REST `/rest/mempool/contents.json`.

Fixes #14765.

ACKs for commit 2d5cf4:

Tree-SHA512: c3e91371bb41f39e79dcef820815e1dc27fb689ca3c4bf3a00467d2215b3baecd44d9792f7a481577a5b7ae1fc6cbaa07b1cd62123b845082eba65b35c2b3ca5

Backport of Core PR14984

Related to D5975

Test Plan:
Compile two versions of bitcoind, one with this patch and the other without,
then record timings for fetching the mempool via REST.

git ch master
ninja bitcoind bitcoin-cli
bitcoind -rest -connect=0     # -connect=0 ensures we do not download any new transactions while testing
bitcoin-cli invalidateblock 000000000000000000e311a3b4f53085a427a22dcc8c790b266d9f882c795564  # some block that is not recent
bitcoin-cli getmempoolinfo    # confirm you have at least thousands of txs in the mempool
for X in {1..100} ; do { time curl localhost:8332/rest/mempool/contents.json ; } 2>> results-without-patch ; done

git ch <this-patch>
ninja bitcoind bitcoin-cli
bitcoind -rest -connect=0     # -connect=0 ensures we do not download any new transactions while testing
bitcoin-cli getmempoolinfo    # confirm you have the same number of transactions in the mempool as the previous test
for X in {1..100} ; do { time curl localhost:8332/rest/mempool/contents.json ; } 2>> results-with-patch ; done

Now compare the average of the timings:

cat results-without-patch | grep real | sed 's/real[ \t]//g' | sed 's/[ms]//g' | awk '{total+=$1; count+=1} END {print total/count}'
cat results-with-patch | grep real | sed 's/real[ \t]//g' | sed 's/[ms]//g' | awk '{total+=$1; count+=1} END {print total/count}'

My results:
Without patch: 0.32937
With patch: 0.17476
~47% reduction

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

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

Details

Provenance
MarcoFalke <falke.marco@gmail.com>Authored on May 15 2019, 15:32
jasonbcoxCommitted on May 8 2020, 14:49
jasonbcoxPushed on May 8 2020, 14:49
Reviewer
Restricted Project
Differential Revision
D6007: Merge #14984: rpc: Speedup getrawmempool when verbose=true
Parents
rABC54c6eab4e0b8: Merge #15463: rpc: Speedup getaddressesbylabel
Branches
Unknown
Tags
Unknown