Page MenuHomePhabricator

faster HexStr => 13% faster blockToJSON
ClosedPublic

Authored by PiRK on Aug 22 2023, 09:54.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCbd61ea8d267b: 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