forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin#31490: refactor: inline
UndoWriteToDisk
and `WriteBlo…
…ckToDisk` to reduce serialization calls 223081e scripted-diff: rename block and undo functions for consistency (Lőrinc) baaa3b2 refactor,blocks: remove costly asserts and modernize affected logs (Lőrinc) fa39f27 refactor,blocks: deduplicate block's serialized size calculations (Lőrinc) dfb2f9d refactor,blocks: inline `WriteBlockToDisk` (Lőrinc) 42bc491 refactor,blocks: inline `UndoWriteToDisk` (Lőrinc) 86b85bb bench: add SaveBlockBench (Lőrinc) 34f9a01 refactor,bench: rename bench/readblock.cpp to bench/readwriteblock.cpp (Lőrinc) Pull request description: `UndoWriteToDisk` and `WriteBlockToDisk` were delegating a subset of their functionality to single-use methods that didn't optimally capture a meaningful chunk of the algorithm, resulting in calculating things twice (serialized size, header size). This change inlines the awkward methods (asserting that all previous behavior was retained), and in separate commits makes the usages less confusing. Besides making the methods slightly more intuitive, the refactorings reduce duplicate calculations as well. The speed difference is insignificant for now (~0.5% for the new `SaveBlockToDiskBench`), but are a cleanup for follow-ups such as bitcoin#31539 ACKs for top commit: ryanofsky: Code review ACK 223081e. Since last review, "Save" was renamed to "Write", uint32_t references were dropped, some log statements and comments were improved as suggested, and a lot of tweaks made to commits and commit messages which should make this easier to review. hodlinator: ACK 223081e TheCharlatan: ACK 223081e andrewtoth: ACK 223081e Tree-SHA512: 951bc8ad3504c510988afd95c561e3e259c6212bd14f6536fe56e8eb5bf5c35c32a368bbdb1d5aea1acc473d7e5bd9cdcde02008a148b05af1f955e413062d5c
- Loading branch information
Showing
20 changed files
with
179 additions
and
204 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 was deleted.
Oops, something went wrong.
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,68 @@ | ||
// Copyright (c) 2023 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 <bench/data/block413567.raw.h> | ||
#include <flatfile.h> | ||
#include <node/blockstorage.h> | ||
#include <primitives/block.h> | ||
#include <primitives/transaction.h> | ||
#include <serialize.h> | ||
#include <span.h> | ||
#include <streams.h> | ||
#include <test/util/setup_common.h> | ||
#include <validation.h> | ||
|
||
#include <cassert> | ||
#include <cstdint> | ||
#include <memory> | ||
#include <vector> | ||
|
||
static CBlock CreateTestBlock() | ||
{ | ||
DataStream stream{benchmark::data::block413567}; | ||
CBlock block; | ||
stream >> TX_WITH_WITNESS(block); | ||
return block; | ||
} | ||
|
||
static void SaveBlockBench(benchmark::Bench& bench) | ||
{ | ||
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)}; | ||
auto& blockman{testing_setup->m_node.chainman->m_blockman}; | ||
const CBlock block{CreateTestBlock()}; | ||
bench.run([&] { | ||
const auto pos{blockman.WriteBlock(block, 413'567)}; | ||
assert(!pos.IsNull()); | ||
}); | ||
} | ||
|
||
static void ReadBlockBench(benchmark::Bench& bench) | ||
{ | ||
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)}; | ||
auto& blockman{testing_setup->m_node.chainman->m_blockman}; | ||
const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)}; | ||
CBlock block; | ||
bench.run([&] { | ||
const auto success{blockman.ReadBlock(block, pos)}; | ||
assert(success); | ||
}); | ||
} | ||
|
||
static void ReadRawBlockBench(benchmark::Bench& bench) | ||
{ | ||
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)}; | ||
auto& blockman{testing_setup->m_node.chainman->m_blockman}; | ||
const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)}; | ||
std::vector<uint8_t> block_data; | ||
blockman.ReadRawBlock(block_data, pos); // warmup | ||
bench.run([&] { | ||
const auto success{blockman.ReadRawBlock(block_data, pos)}; | ||
assert(success); | ||
}); | ||
} | ||
|
||
BENCHMARK(SaveBlockBench, benchmark::PriorityLevel::HIGH); | ||
BENCHMARK(ReadBlockBench, benchmark::PriorityLevel::HIGH); | ||
BENCHMARK(ReadRawBlockBench, benchmark::PriorityLevel::HIGH); |
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
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
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
Oops, something went wrong.