Page MenuHomePhabricator

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

Authored by jasonbcox on May 8 2020, 00:14.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

[Bot Message]
One or more PR numbers were detected in the summary.
Links to those PRs have been inserted into the summary for reference.

jasonbcox edited the test plan for this revision. (Show Details)
This revision is now accepted and ready to land.May 8 2020, 00:51