From 83a425d25af033086744c1c8c892015014ed46bd Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 1 May 2020 17:31:38 -0700 Subject: compressor: use a prevector in compressed script serialization Use a prevector for stack allocation instead of heap allocation during script compression and decompression. These functions were doing millions of unnecessary heap allocations during IBD. We introduce a CompressedScript type alias for this prevector. It is size 33 as that is the maximum size of a compressed script. Fix the DecompressScript header to match the variable name from compressor.cpp Signed-off-by: William Casarin --- src/compressor.cpp | 4 ++-- src/compressor.h | 20 ++++++++++++++++---- src/test/compress_tests.cpp | 8 ++++---- src/test/fuzz/script.cpp | 8 +++++--- 4 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/compressor.cpp b/src/compressor.cpp index a70306d320..ef3135e7a5 100644 --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -52,7 +52,7 @@ static bool IsToPubKey(const CScript& script, CPubKey &pubkey) return false; } -bool CompressScript(const CScript& script, std::vector &out) +bool CompressScript(const CScript& script, CompressedScript& out) { CKeyID keyID; if (IsToKeyID(script, keyID)) { @@ -92,7 +92,7 @@ unsigned int GetSpecialScriptSize(unsigned int nSize) return 0; } -bool DecompressScript(CScript& script, unsigned int nSize, const std::vector &in) +bool DecompressScript(CScript& script, unsigned int nSize, const CompressedScript& in) { switch(nSize) { case 0x00: diff --git a/src/compressor.h b/src/compressor.h index 478bfff0b6..40b2496f06 100644 --- a/src/compressor.h +++ b/src/compressor.h @@ -6,14 +6,26 @@ #ifndef BITCOIN_COMPRESSOR_H #define BITCOIN_COMPRESSOR_H +#include #include #include