-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
152e8ba Use salted hasher instead of nonce in sigcache (Jeremy Rubin) 5495fa5 Add Hash Padding Microbenchmarks (Jeremy Rubin) Pull request description: This PR replaces nonces in two places with pre-salted hashers. The nonce is chosen to be 64 bytes long so that it forces the SHA256 hasher to process the chunk. This leaves the next 64 (or 56 depending if final chunk) open for data. In the case of the script execution cache, this does not make a big performance improvement because the nonce was already properly padded to fit into one buffer, but does make the code a little simpler. In the case of the sig cache, this should reduce the hashing overhead slightly because we are less likely to need an additional processing step. I haven't benchmarked this, but back of the envelope it should reduce the hashing by one buffer for all combinations except compressed public keys with compact signatures. ACKs for top commit: ryanofsky: Code review ACK 152e8ba. No code changes, just rebase since last review and expanded commit message Tree-SHA512: b133e902fd595cfe3b54ad8814b823f4d132cb2c358c89158842ae27daee56ab5f70cde2585078deb46f77a6e7b35b4cc6bba47b65302b7befc2cff254bad93d
- Loading branch information
Showing
4 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2015-2018 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <bench/bench.h> | ||
#include <hash.h> | ||
#include <random.h> | ||
#include <uint256.h> | ||
|
||
|
||
static void PrePadded(benchmark::State& state) | ||
{ | ||
|
||
CSHA256 hasher; | ||
|
||
// Setup the salted hasher | ||
uint256 nonce = GetRandHash(); | ||
hasher.Write(nonce.begin(), 32); | ||
hasher.Write(nonce.begin(), 32); | ||
uint256 data = GetRandHash(); | ||
while (state.KeepRunning()) { | ||
unsigned char out[32]; | ||
CSHA256 h = hasher; | ||
h.Write(data.begin(), 32); | ||
h.Finalize(out); | ||
} | ||
} | ||
|
||
BENCHMARK(PrePadded, 10000); | ||
|
||
static void RegularPadded(benchmark::State& state) | ||
{ | ||
CSHA256 hasher; | ||
|
||
// Setup the salted hasher | ||
uint256 nonce = GetRandHash(); | ||
uint256 data = GetRandHash(); | ||
while (state.KeepRunning()) { | ||
unsigned char out[32]; | ||
CSHA256 h = hasher; | ||
h.Write(nonce.begin(), 32); | ||
h.Write(data.begin(), 32); | ||
h.Finalize(out); | ||
} | ||
} | ||
|
||
BENCHMARK(RegularPadded, 10000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters