mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 15:11:38 +00:00
WIP: coins: cache UTXO outpoint hash codes #35195
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35195
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/noexcept-false"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Draft status: Current master uses
SaltedCoinsCacheHasherfor the UTXO cache after #35215. I need to retarget this patch and remeasure it before taking it out of draft. The benchmarks below use the older bases shown.Problem: On this PR’s base,
CCoinsMapusesSaltedOutpointHasherfor UTXO cache lookups. Since #16957 marked the hashernoexcept,libstdc++no longer stores cached hash codes in unordered-map nodes.#16957 optimized for memory: the original benchmark reported about
9.4%lower peak RSS, but also about1.6%slower runtime from recomputing hashes. This PR takes the opposite side of that same tradeoff for the UTXO cache: allowlibstdc++to store one cached hash code per unordered-map node, avoiding repeatedSipHashwork in rehashing and some table operations.Benchmarks consistently favored cached hash codes:
-dbcache.AssumeUTXOloading showed the strongest signal, up to about11%faster. This is the cleanest dbcache-exercising benchmark here because it avoids block download and full validation work, so the coins-cache effect is less diluted.SipHashoptimization work showed about3%faster on an Intel N150 after theSipHashchange.libstdc++by up to one cachedsize_tper node. In practice, recent Massif runs were roughly neutral at moderate dbcache values, while a very large dbcache run showed the expected higher peak.For
CCoinsMap, no allocator sizing change is needed since itsPoolAllocatorblock size already reserves implementation-defined node overhead and explicitly accounts for implementations where "the hash value is stored as well". That assumption remained in the code after the #16957noexceptchange disabled cached hash codes for this hasher, so there is no memory calculation to restore in this PR.This is also consistent with concerns raised in the original #16957 discussion: reviewers noted the
noexceptchange was slower, that it imposed a penalty when memory was not limiting, and that "it might be possible to regain the performance loss by caching the hash ourselves." This PR letslibstdc++do that caching for us.Fix: Revert #16957's
SaltedOutpointHashernoexceptchange, then document the now-intentionalnoexcept(false)contract and add a focused unit test.The implementation still does not throw. Only the exception specification used by
libstdc++'s unordered-map node policy changes: for a fast hash functor that may throw,libstdc++caches hash codes in nodes.The test checks both inputs to that policy:
SaltedOutpointHasheris not nothrow-invocablelibstdc++, it remains classified as a fast hashThis mirrors the type-level contract style used in
libstdc++'s own hash tests.Reproducer:
Fresh reindex-chainstate run
Earlier supporting measurements
Original #16957 result:
#16957 also showed that increasing dbcache on the
noexceptbranch could recover performance while staying below old memory use:Earlier cached-hash measurements:
Later
noexceptremoval measurements:Memory observations:
Compatibility with input-fetcher and `SipHash` work
This change has been in my queue for more than a year, so some supporting measurements are older and were collected while adjacent input-fetcher and
SipHashwork was still evolving. The relevant compatibility measurements are documented in this #31132 review comment.After input fetching,
SipHashinlining, andnoexceptremoval on an Intel N150:After input fetching,
SipHashinlining, andnoexceptremoval on an M4 Max:The Intel N150 comparison supports cached hash codes helping alongside the other changes. The M4 measurement does not identify the C++ library, so I cannot attribute its improvement to this mechanism.
libc++already stores hash codes regardless ofnoexcept.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.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.
Concept ACK
16e77fdf13This PR attempts to improve performance, by allowing
CCoinsMapkey hashes to be cached.In general, the tradeoff between extra memory and extra CPU is not clear, but in this case benchmarks indicate that caching (more memory, less CPU) results in faster execution, therefore it should be applied.
Code-wise I don't see issues or dangers reverting the
noexcepton the hasher tonoexcept(false). Left some nits.Nit: I suggest removing the blank lines here. A blank line as a separator between project and external include makes sense, but these are not needed.
Nit: I suggest adding a blank line here, to show that the two parts are separate checks.
Nit: In this particular case, I don't see a value in separating into 2 commits, I would prefer a single commit.
Have you considered controlling hash-caching via
__is_fast_hash(as described in the mentioned link)? Seems more clear than abusing 'noexcept'. Or that would not work on other platforms?🐙 This pull request conflicts with the target branch and needs rebase.
🔵 Suggestion · The cache-capacity change is missing from the release notes
On libstdc++ builds, hash caching reduces UTXO capacity at a fixed
-dbcacheand can increase memory use when the cache never fills, but the PR lacks an operator-facing note.Location:
src/coins.h:253(head).Review coverage was incomplete.
Reviewed:
61046c54b910· Review report · Previous reportspermalink