Skip to content

RPC: Add reserve member function to `UniValue` and use it in `blockToJSON` function

This PR is motivated by https://github.com/bitcoin/bitcoin/issues/30495#issuecomment-2444881418, It adds a reserve member function to UniValue and applies it within the blockToJSON function to pre-allocate memory, minimizing reallocation's.

Slight performance increase in verbosity 1

On master:

ns/op op/s err% total benchmark
190,342 5,254 2.3% 0.01 BlockToJsonVerbose1
34,812,292 28.73 1.0% 0.38 BlockToJsonVerbose2
34,457,167 29.02 1.0% 0.38 BlockToJsonVerbose3

On this PR:

ns/op op/s err% total benchmark
172,278 5,805 0.7% 0.01 BlockToJsonVerbose1
33,720,584 29.66 0.4% 0.37 BlockToJsonVerbose2
33,884,417 29.51 1.2% 0.38 BlockToJsonVerbose3

Merge request reports

Loading