HomePhabricator

faster HexStr => 13% faster blockToJSON

Description

faster HexStr => 13% faster blockToJSON

Summary:
std::string's push_back is rather slow because it needs to check & update the string size. For
HexStr the output string size is already easily know, so we can initially create the string with
the correct size and then just assign the data.

HexStr is heavily usd in blockToJSON, so this change is a noticeable benefit. Benchmark on an i7-8700 @3.2GHz:

  • 71,315,461.00 ns/op master
  • 62,842,490.00 ns/op this commit

So this little change makes blockToJSON about ~13% faster.

This is a backport of core#21173

Test Plan: ninja all check-all bench-bitcoin

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

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

Details

Provenance
Martin Ankerl <martin.ankerl@gmail.com>Authored on Feb 14 2021, 11:10
PiRKCommitted on Aug 22 2023, 11:39
PiRKPushed on Aug 22 2023, 11:39
Reviewer
Restricted Project
Differential Revision
D14396: faster HexStr => 13% faster blockToJSON
Parents
rABC6432979c91b1: test: Change feature_config_args.py not to rely on strange regtest=0 behavior
Branches
Unknown
Tags
Unknown