refactor: use `SpanReader` in `PrevectorDeserialize`
What changed, and why it matters
This is a code cleanup change in Bitcoin Core's internal benchmarking code. It swaps a mutable data stream for a simple read-only view in a performance test, and removes an unused helper function called Rewind(). There is no security issue here.
No security action needed. This is a benign refactor of benchmark-only code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the PrevectorDeserialize benchmark to use SpanReader instead of DataStream. Previously the benchmark built a DataStream once, deserialized it 1000 times in a loop, and called Rewind() after each benchmark iteration to reset the read position. The new code constructs a fresh SpanReader over the same serialized bytes for each benchmark run, making Rewind() unnecessary. The Rewind() method is removed from DataStream because this benchmark was its only remaining caller. The serialization counts are also adjusted so exactly 1000 elements are produced, removing the extra stale element that existed only to avoid fully consuming the stream.
Changed components
src/bench/prevector.cppsrc/streams.hInspect captured patch +5 / −20
diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp
index 8d386ec2..e842aec4 100644
--- a/src/bench/prevector.cpp
+++ b/src/bench/prevector.cpp
@@ -66,22 +66,22 @@ static void PrevectorResize(benchmark::Bench& bench)
template <typename T>
static void PrevectorDeserialize(benchmark::Bench& bench)
{
- DataStream s0{};
+ DataStream data{};
prevector<CScriptBase::STATIC_SIZE, T> t0;
t0.resize(CScriptBase::STATIC_SIZE);
for (auto x = 0; x < 900; ++x) {
- s0 << t0;
+ data << t0;
}
t0.resize(100);
- for (auto x = 0; x < 101; ++x) {
- s0 << t0;
+ for (auto x = 0; x < 100; ++x) {
+ data << t0;
}
bench.batch(1000).run([&] {
+ SpanReader s0{data};
prevector<CScriptBase::STATIC_SIZE, T> t1;
for (auto x = 0; x < 1000; ++x) {
s0 >> t1;
}
- s0.Rewind();
});
}
diff --git a/src/streams.h b/src/streams.h
index 4fc5879f..6ef9d164 100644
--- a/src/streams.h
+++ b/src/streams.h
@@ -206,21 +206,6 @@ public:
value_type* data() { return vch.data() + m_read_pos; }
const value_type* data() const { return vch.data() + m_read_pos; }
- bool Rewind(std::optional<size_type> n = std::nullopt)
- {
- // Total rewind if no size is passed
- if (!n) {
- m_read_pos = 0;
- return true;
- }
- // Rewind by n characters if the buffer hasn't been compacted yet
- if (*n > m_read_pos)
- return false;
- m_read_pos -= *n;
- return true;
- }
-
-
//
// Stream subset
//
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.