rpc: Speedup getrawmempool when verbose=true#14984
Conversation
|
Thanks @MarcoFalke, the report says >100k. I don't think this matters for small mempool. |
|
mempool with 100k transactions: Before: After:
Can you point me in the right direction?
What should I test? |
|
Could call |
|
I don't think that's "public"? |
|
It's declared publicly, may be |
|
Looks like it could be either private or have another name. I don't have strong preference as the goal is to avoid the duplicate key check, but I'm more inclined to not use the "internal/private/reserved" method. OTOH it would be reasonable to add duplicate key checks to Maybe we should rename |
b243d5e to
26b5806
Compare
|
@MarcoFalke not sure about the benchmark. This is a small change to fix the original issue. But I think univalue should have an official API to avoid duplicate key checks and so the benchmark should be there, or am I wrong? Pushed with your suggestion. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
Co-Authored-By: MarcoFalke <[email protected]>
26b5806 to
2d5cf4c
Compare
|
Rebased, switched to |
710a713 rpc: Speedup getaddressesbylabel (João Barbosa) Pull request description: Fixes #15447. Same approach of #14984, this change avoids duplicate key check when building the JSON response in memory. ACKs for commit 710a71: MarcoFalke: utACK 710a713 ryanofsky: utACK 710a713. Just new comments and assert since last review. Tree-SHA512: 77c95df9ff3793e348619aa070e6fd36df9da1b461d708ab146652cb3699f1a472ef6eb38dafdb8374375cbc97daef07635fcb0501961f167a023309513742e2
|
Anything left to do here? This is pretty much the same as #15463. |
2d5cf4c 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 bitcoin#14765. ACKs for commit 2d5cf4: Tree-SHA512: c3e91371bb41f39e79dcef820815e1dc27fb689ca3c4bf3a00467d2215b3baecd44d9792f7a481577a5b7ae1fc6cbaa07b1cd62123b845082eba65b35c2b3ca5
2d5cf4c 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 bitcoin#14765. ACKs for commit 2d5cf4: Tree-SHA512: c3e91371bb41f39e79dcef820815e1dc27fb689ca3c4bf3a00467d2215b3baecd44d9792f7a481577a5b7ae1fc6cbaa07b1cd62123b845082eba65b35c2b3ca5
|
I've seen this PR a bit late (just after it got merged), but fwiw here is some real world improvement data: Time it takes to GET in v0.18.0 : v0.18.0 with the proposed change: Which for my sample is a reduction of 16.2s or 30%!! 🎉 |
|
Thanks @0xB10C for the feedback. |
|
This is an easy backport but I'm not sure if it's a candidate. |
|
@laanwj I'm going to backport this 0.18.1, not sure if milestone should be changed. |
|
@promag the milestone can remain 0.19.0 here, your backport PR will get 0.18.1. |
|
@0xB10C after all this is not a backport candidate. |
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 [[bitcoin/bitcoin#14984 | 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
710a713 rpc: Speedup getaddressesbylabel (João Barbosa) Pull request description: Fixes bitcoin#15447. Same approach of bitcoin#14984, this change avoids duplicate key check when building the JSON response in memory. ACKs for commit 710a71: MarcoFalke: utACK 710a713 ryanofsky: utACK 710a713. Just new comments and assert since last review. Tree-SHA512: 77c95df9ff3793e348619aa070e6fd36df9da1b461d708ab146652cb3699f1a472ef6eb38dafdb8374375cbc97daef07635fcb0501961f167a023309513742e2
2d5cf4c 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 bitcoin#14765. ACKs for commit 2d5cf4: Tree-SHA512: c3e91371bb41f39e79dcef820815e1dc27fb689ca3c4bf3a00467d2215b3baecd44d9792f7a481577a5b7ae1fc6cbaa07b1cd62123b845082eba65b35c2b3ca5
Merge bitcoin PRs: bitcoin#14683, bitcoin#15841, bitcoin#14984 and bitcoin#15943
2d5cf4c 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 bitcoin#14765. ACKs for commit 2d5cf4: Tree-SHA512: c3e91371bb41f39e79dcef820815e1dc27fb689ca3c4bf3a00467d2215b3baecd44d9792f7a481577a5b7ae1fc6cbaa07b1cd62123b845082eba65b35c2b3ca5

Instead of calling
pushKV(hash, info), which incurs in duplicate key checks, call__pushKVwhich (currently) doesn't.Improves RPC
getrawmempooland REST/rest/mempool/contents.json.Fixes #14765.