HomePhabricator

ConnectBlock: don't serialize block hash twice

Description

ConnectBlock: don't serialize block hash twice

Summary:

In the validation:block_connected tracepoint, we call block->GetHash(), which
ends up calling CBlockHeader::GetHash(), executing around 8000 serialization
instructions. We don't need to do this extra work, because block->GetHash() is
already called further up in the function. Let's save that value as a local
variable and re-use it in our tracepoint so there is no unnecessary tracepoint
overhead.

Shave off an extra 100 or so instructions from the validation:block_connected
tracepoint by reusing a nearby GetTimeMicros(). This brings the tracepoint down
to 54 instructions. Still high, but much better than the previous ~154 and
8000 instructions which it was originally.

Backport of core#23819.

Depends on D12674.

Test Plan:

sudo bpftrace ../contrib/tracing/connectblock_benchmark.bt 0 0 25

Reviewers: #bitcoin_abc, PiRK, sdulfari

Reviewed By: #bitcoin_abc, PiRK, sdulfari

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

Details

Provenance
William Casarin <jb55@jb55.com>Authored on Dec 19 2021, 20:52
FabienCommitted on Nov 30 2022, 18:49
FabienPushed on Nov 30 2022, 18:49
Reviewer
Restricted Project
Differential Revision
D12705: ConnectBlock: don't serialize block hash twice
Parents
rABC8e9ae4ef68c5: tracing: drop block_connected hash.toString() arg
Branches
Unknown
Tags
Unknown