mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge bitcoin/bitcoin#18847: compressor: use a prevector in CompressScript serialization [ZAP1]
83a425d25acompressor: use a prevector in compressed script serialization (William Casarin) Pull request description: This function was doing millions of unnecessary heap allocations during IBD. I'm start to catalog unnecessary heap allocations as a pet project of mine: as-zero-as-possible-alloc IBD. This is one small step. before:  after:  ~should I type alias this?~ *I type aliased it* This is a part of the Zero Allocations Project #18849 (ZAP1). This code came up as a place where many allocations occur. ACKs for top commit: Empact: ACK83a425d25aelichai: tACK83a425d25asipa: utACK83a425d25aTree-SHA512: f0ffa6ab0ea1632715b0b76362753f9f6935f05cdcc80d85566774401155a3c57ad45a687942a1806d3503858f0bb698da9243746c8e2edb8fdf13611235b0e0
This commit is contained in:
@@ -43,7 +43,7 @@ FUZZ_TARGET_INIT(script, initialize_script)
|
||||
if (!script_opt) return;
|
||||
const CScript script{*script_opt};
|
||||
|
||||
std::vector<unsigned char> compressed;
|
||||
CompressedScript compressed;
|
||||
if (CompressScript(script, compressed)) {
|
||||
const unsigned int size = compressed[0];
|
||||
compressed.erase(compressed.begin());
|
||||
@@ -143,10 +143,12 @@ FUZZ_TARGET_INIT(script, initialize_script)
|
||||
|
||||
{
|
||||
const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
CompressedScript compressed_script;
|
||||
compressed_script.assign(bytes.begin(), bytes.end());
|
||||
// DecompressScript(..., ..., bytes) is not guaranteed to be defined if the bytes vector is too short
|
||||
if (bytes.size() >= 32) {
|
||||
if (compressed_script.size() >= 32) {
|
||||
CScript decompressed_script;
|
||||
DecompressScript(decompressed_script, fuzzed_data_provider.ConsumeIntegral<unsigned int>(), bytes);
|
||||
DecompressScript(decompressed_script, fuzzed_data_provider.ConsumeIntegral<unsigned int>(), compressed_script);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user