HomePhabricator

rpc: Reduce Univalue push_backV peak memory usage in listtransactions

Description

rpc: Reduce Univalue push_backV peak memory usage in listtransactions

Summary:

Currently the RPC will have the same data stored thrice:
 - UniValue ret (memory filled by ListTransactions)
 - std::vector<UniValue> vec (constructed by calling push_backV)
 - UniValue result (the actual result, memory filled by push_backV)

Fix this by filling the memory only once:
 - std::vector<UniValue> ret (memory filled by ListTransactions)
 - Pass iterators to push_backV instead of creating a full copy
 - Move memory into UniValue result instead of copying it

Backport of core#25464.

Test Plan:

ninja check-all

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D16276

Details

Provenance
MacroFake <falke.marco@gmail.com>Authored on Jun 23 2022, 19:48
FabienCommitted on Jun 5 2024, 17:49
FabienPushed on Jun 5 2024, 17:49
Reviewer
Restricted Project
Differential Revision
D16276: rpc: Reduce Univalue push_backV peak memory usage in listtransactions
Parents
rABCe437874f1452: CBlockLocator: performance-move-const-arg Clang tidy fixups
Branches
Unknown
Tags
Unknown