Skip to content

util: Faster std::byte (pre)vector (un)serialize

Currently, large vectors of std::byte are (un)serialized byte-by-byte, which is slow. Fix this, by enabling the already existing optimization for them.

On my system this gives a 10x speedup for ./src/bench/bench_bitcoin --filter=PrevectorDeserializeTrivial, when std::byte are used:

diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp
index 2524e215e4..76b16bc34e 100644
--- a/src/bench/prevector.cpp
+++ b/src/bench/prevector.cpp
@@ -17,7 +17,7 @@ struct nontrivial_t {
 static_assert(!std::is_trivially_default_constructible<nontrivial_t>::value,
               "expected nontrivial_t to not be trivially constructible");
 
-typedef unsigned char trivial_t;
+typedef std::byte trivial_t;
 static_assert(std::is_trivially_default_constructible<trivial_t>::value,
               "expected trivial_t to be trivially constructible");
 

However, the optimization does not cover signed char. Fix that as well.

Merge request reports

Loading