Skip to content

Conversation

@martinus
Copy link
Contributor

The benchmark BlockToJsonVerbose only tests generating (and destroying)
the JSON data structure, but serializing into a string is also a
performance critical aspect of the RPC calls.

Extracts test setup into a struct TestBlockAndIndex, and uses it in
both BlockToJsonVerbose and BlockToJsonVerboseWrite.

Also, use ankerl::nanobench::doNotOptimizeAway to make sure the compiler
can't optimize the result of the calls away.

Here are benchmark results on my Intel i7-8700:

ns/op op/s err% ins/op cyc/op IPC bra/op miss% total benchmark
71,807,017.00 13.93 0.4% 555,782,961.00 220,788,645.00 2.517 102,279,341.00 0.4% 0.80 BlockToJsonVerbose
27,916,835.00 35.82 0.1% 235,084,034.00 89,033,525.00 2.640 42,911,139.00 0.3% 0.32 BlockToJsonVerboseWrite

@fanquake fanquake added the Tests label Feb 13, 2021
@martinus martinus force-pushed the 2021-02-benchmark-BlockToJsonVerboseWrite branch from f7ab0f8 to baeb893 Compare February 13, 2021 09:27
The benchmark BlockToJsonVerbose only tests generating (and destroying)
the JSON data structure, but serializing into a string is also a
performance critical aspect of the RPC calls.

Also, use ankerl::nanobench::doNotOptimizeAway to make sure the compiler
can't optimize the result of the calls away.
@martinus martinus force-pushed the 2021-02-benchmark-BlockToJsonVerboseWrite branch from baeb893 to e3e0a24 Compare February 13, 2021 12:14
@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 13, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@practicalswift
Copy link
Contributor

Concept ACK

Really like nanobench BTW: a really nice addition to Bitcoin Core!

@martinus
Copy link
Contributor Author

Really like nanobench BTW: a really nice addition to Bitcoin Core!

Thanks! Probably not widely known, but it is really helpful to run a benchmark in an endless loop like so:

NANOBENCH_ENDLESS=BlockToJsonVerbose ./src/bench/bench_bitcoin -filter=BlockToJsonVerbose

And then fire up a profiler like perf top or hotspot to see where all the cycles are used up :)

@laanwj
Copy link
Member

laanwj commented Mar 1, 2021

Code review ACK e3e0a24

@laanwj laanwj merged commit 05e821e into bitcoin:master Mar 1, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 1, 2021
e3e0a24 Add benchmark to write JSON into a string (Martin Ankerl)

Pull request description:

  The benchmark `BlockToJsonVerbose` only tests generating (and destroying)
  the JSON data structure, but serializing into a string is also a
  performance critical aspect of the RPC calls.

  Extracts test setup into a `struct TestBlockAndIndex`, and uses it in
  both `BlockToJsonVerbose` and `BlockToJsonVerboseWrite`.

  Also, use `ankerl::nanobench::doNotOptimizeAway` to make sure the compiler
  can't optimize the result of the calls away.

  Here are benchmark results on my Intel i7-8700:

  |               ns/op |                op/s |    err% |          ins/op |          cyc/op |    IPC |         bra/op |   miss% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
  |       71,807,017.00 |               13.93 |    0.4% |  555,782,961.00 |  220,788,645.00 |  2.517 | 102,279,341.00 |    0.4% |      0.80 | `BlockToJsonVerbose`
  |       27,916,835.00 |               35.82 |    0.1% |  235,084,034.00 |   89,033,525.00 |  2.640 |  42,911,139.00 |    0.3% |      0.32 | `BlockToJsonVerboseWrite`

ACKs for top commit:
  laanwj:
    Code review ACK e3e0a24

Tree-SHA512: bc4d6d1588d47d4bd7af8e7908e44b8561bc391a2d73eccd7c0aa37fc40e8a9ce1fa1f3c29b416eef24a73c6bce3036839c0bbfe1b8dbd6d1bba3718b7ca5383
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants