AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 15 Bitcoin

bench: make `MerkleRoot` benchmark more representative

Public commit record

What the developer wrote

Authored by Lőrinc

85/100 · Strong
bench: make `MerkleRoot` benchmark more representative

Two versions are run now, one with the mutation calculations, the other without.
To avoid unwanted compiler optimizations, we assert the expected hash, which should inhibit aggressive optimization.

To make the benchmark more similar to production `ComputeMerkleRoot` call sites, the input leaves-copying is made explicit before each run.

> ./build/bin/bench_bitcoin -filter='MerkleRoot.*' -min-time=1000

| ns/leaf | leaf/s | err% | total | benchmark
|--------------------:|--------------------:|--------:|----------:|:----------
| 44.18 | 22,634,858.70 | 0.0% | 1.10 | `MerkleRoot`
| 44.66 | 22,390,601.03 | 0.0% | 1.10 | `MerkleRootWithMutation`

Massif memory measurements show the excessive memory reservations:

MB
1.332^ :
| # :
| # :
| # :
| # :
| # @ :
| # @ :
| # @ :
| # @ :
| # @ :
| # @ :
| # @ :
| # @ :
| #::::@::::::::::::::::::::::::::::::::::::::::::::::::::::::@:::::@::::
| #: ::@::::: :::::::: :: ::: :::::: : : :: ::: ::: : : : ::::@:::::@::::
| #: ::@::::: :::::::: :: ::: :::::: : : :: ::: ::: : : : ::::@:::::@::::
| #: ::@::::: :::::::: :: ::: :::::: : : :: ::: ::: : : : ::::@:::::@::::
| #: ::@::::: :::::::: :: ::: :::::: : : :: ::: ::: : : : ::::@:::::@::::
| #: ::@::::: :::::::: :: ::: :::::: : : :: ::: ::: : : : ::::@:::::@::::
| #: ::@::::: :::::::: :: ::: :::::: : : :: ::: ::: : : : ::::@:::::@::::
0 +----------------------------------------------------------------------->s
0 226.2

showing the reallocations clearly in the stacks:
97.87% (1,366,841B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->41.25% (576,064B) 0x969717: allocate (new_allocator.h:151)
| ->41.25% (576,064B) 0x969717: allocate (allocator.h:203)
| ->41.25% (576,064B) 0x969717: allocate (alloc_traits.h:614)
| ->41.25% (576,064B) 0x969717: _M_allocate (stl_vector.h:387)
| ->41.25% (576,064B) 0x969717: _M_realloc_append<const uint256&> (vector.tcc:572)
| ->41.25% (576,064B) 0x969717: push_back (stl_vector.h:1427)
| ->41.25% (576,064B) 0x969717: ComputeMerkleRoot(std::vector<uint256, std::allocator<uint256> >, bool*) (merkle.cpp:55)
| ->41.25% (576,064B) 0x2235A7: operator() (merkle_root.cpp:31)
| ->41.25% (576,064B) 0x2235A7: ankerl::nanobench::Bench& ankerl::nanobench::Bench::run<MerkleRoot(ankerl::nanobench::Bench&)::{lambda()

Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This change only updates an internal performance benchmark for the Merkle root calculation. It does not alter the actual Bitcoin consensus or networking code that runs on nodes, so it cannot directly affect security, funds, or network behavior.

Recommended action

No security action needed. This is a benchmark-only change and can be reviewed as normal code quality/performance tooling work.

Security signals we found

No strong security signals were identified.

Risk score

Why this scored 15/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 0/15
Confidence 10/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.