Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

univalue optimizations: move semantics, reduce temporary strings #79

Closed
wants to merge 2 commits into from

Conversation

martinus
Copy link

  • Introducing move semantics for pushKV and push_back. In many use cases
    the const& calls unnecessarily create a copy of the argument, when
    objects can be moved this does not happen.

  • Reduce creation of temporary strings. json_escape and write now
    appends to an existing string instead of creating a temporary.

  • Use std::to_string instead of std::ostringstream for setNumStr,
    which is much faster than creating a temporary string.

In a benchmark with Bitcoin's BlockToJsonVerbose, using these move
methods where possible speeds up JSON generation by about a factor of 2.

You can see some benchmarks here: bitcoin/bitcoin#20999

* Introducing move semantics for pushKV and push_back. In many use cases
  the const& calls unnecessarily create a copy of the argument, when
  objects can be moved this does not happen.

* Reduce creation of temporary strings. `json_escape` and `write` now
  appends to an existing string instead of creating a temporary.

* Use `std::to_string` instead of `std::ostringstream` for `setNumStr`,
  which is much faster than creating a temporary string.

In a benchmark with Bitcoin's BlockToJsonVerbose, using these move
methods where possible speeds up JSON generation by about a factor of 2.
When known that it is just a char that's appended, use character instead of a string. This can use a different overload in std::string, which  is faster.
@martinus
Copy link
Author

martinus commented Sep 2, 2021

Closing the PR due to zero interest in the last 8 months.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant