mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
5d82d92affrpc: reserve space for `UniValue` variables in `blockToJSON` (ismaelsadeeq)6a506d5c37UniValue: add reserve member function (ismaelsadeeq)bd461195f4bench: support benching all verbosity of `BlockToJson` (ismaelsadeeq) Pull request description: 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. <details> <summary>Slight performance increase in verbosity 1</summary> 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` | </details> ACKs for top commit: maflcko: review ACK5d82d92aff🐀 l0rinc: ACK5d82d92affachow101: ACK5d82d92affEunovo: Re-ACK5d82d92affTree-SHA512: bdd2c1bcdc4d060d30ad3be0b10f0d722dda0c2286bc4156af851503220e8854e76a4dc53456826b543c110982455268838172d3a1026eee754d4c673b48ea05