mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-31 10:41:08 +00:00
5d82d92aff7c11ce17ee809c060e37f73a8a687a rpc: reserve space for `UniValue` variables in `blockToJSON` (ismaelsadeeq)
6a506d5c37d1cb179b4e818dfbeaff5834420a33 UniValue: add reserve member function (ismaelsadeeq)
bd461195f4b3a3c53366c8f197e7701836cab053 bench: 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 ACK 5d82d92aff7c11ce17ee809c060e37f73a8a687a 🐀
l0rinc:
ACK 5d82d92aff7c11ce17ee809c060e37f73a8a687a
achow101:
ACK 5d82d92aff7c11ce17ee809c060e37f73a8a687a
Eunovo:
Re-ACK 5d82d92aff
Tree-SHA512: bdd2c1bcdc4d060d30ad3be0b10f0d722dda0c2286bc4156af851503220e8854e76a4dc53456826b543c110982455268838172d3a1026eee754d4c673b48ea05