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

optimization: introduce `PresaltedSipHasher` for repeated hashing

Public commit record

What the developer wrote

Authored by Lőrinc

73/100 · Adequate
optimization: introduce `PresaltedSipHasher` for repeated hashing

Replaces the `SipHashUint256Extra` function with the `PresaltedSipHasher` class that caches the constant-salted state (v[0-3] after XORing with keys).
This avoids redundant XOR operations when hashing multiple values with the same keys, benefiting use cases like `SaltedOutpointHasher`.

This essentially brings the precalculations in the `CSipHasher` constructor to the `uint256`-specialized SipHash implementation.

> cmake -B build -DBUILD_BENCH=ON -DCMAKE_BUILD_TYPE=Release && cmake --build build -j$(nproc) && build/src/bench/bench_bitcoin -filter='SaltedOutpointHasherBench.*' -min-time=10000

> C++ compiler .......................... AppleClang 16.0.0.16000026

| ns/op | op/s | err% | total | benchmark
|--------------------:|--------------------:|--------:|----------:|:----------
| 57.27 | 17,462,299.19 | 0.1% | 11.02 | `SaltedOutpointHasherBench_create_set`
| 11.24 | 88,997,888.48 | 0.3% | 11.04 | `SaltedOutpointHasherBench_hash`
| 13.91 | 71,902,014.20 | 0.2% | 11.01 | `SaltedOutpointHasherBench_match`
| 13.29 | 75,230,390.31 | 0.1% | 11.00 | `SaltedOutpointHasherBench_mismatch`

compared to master:
create_set - 17,462,299.19/17,065,922.04 - 2.3% faster
hash - 88,997,888.48/83,576,684.83 - 6.4% faster
match - 71,902,014.20/68,985,850.12 - 4.2% faster
mismatch - 75,230,390.31/71,942,033.47 - 4.5% faster

> C++ compiler .......................... GNU 13.3.0

| ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
| 135.38 | 7,386,349.49 | 0.0% | 1,078.19 | 486.16 | 2.218 | 119.56 | 1.1% | 11.00 | `SaltedOutpointHasherBench_create_set`
| 23.67 | 42,254,558.08 | 0.0% | 247.01 | 85.01 | 2.906 | 4.00 | 0.0% | 11.00 | `SaltedOutpointHasherBench_hash`
| 58.95 | 16,962,220.14 | 0.1% | 446.55 | 211.74 | 2.109 | 20.86 | 1.4% | 11.01 | `SaltedOutpointHasherBench_match`
| 76.98 | 12,991,047.69 | 0.1% | 548.93 | 276.50 | 1.985 | 20.25 | 2.3% | 10.72 | `SaltedOutpointHasherBench_mismatch`

compared to master:
create_set - 7,386,349.49/7,312,133.16 - 1% faster
hash - 42,254,558.08/41,978,882.62 - 0.6% faster
match - 16,962,220.14/16,549,695.42 - 2.4% faster
mismatch - 12,991,047.69/12,713,595.35 - 2% faster

Co-authored-by: sipa <pieter@wuille.net>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This is a routine performance optimization for Bitcoin Core's hash tables. It replaces a function that re-computed part of its internal state on every call with a small helper class that pre-computes and reuses that state. The change is purely about speed and does not alter the final hash results. There is no indication it fixes a security bug or introduces a vulnerability.

Recommended action

No security action required. Treat as a normal code-quality/performance change. Reviewers may optionally verify that the cached initial state matches the original CSipHasher constructor constants and that the operator() logic is identical to the removed function body.

Security signals we found

01

No security-relevant signals present in the commit message or diff.

02

Change is explicitly described as an optimization by the author.

03

Existing test coverage is updated to preserve correctness invariants.

04

No new dependencies, network exposure, or privilege changes.

Risk score

Why this scored 18/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 5/15
Confidence 9/10
Evidence quality 4/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.