Avoid unnecessary allocations in AccumulatorStack

replacing the vector with an array resulted in a .45+-.10 % speedup.

closes https://github.com/official-stockfish/Stockfish/pull/6352

no functional change
This commit is contained in:
Carlos Esparza
2025-11-01 11:12:03 +01:00
committed by Joost VandeVondele
parent fa3b4ef5af
commit 11ab4cde07
2 changed files with 3 additions and 10 deletions
-2
View File
@@ -106,8 +106,6 @@ class Network {
template<IndexType Size>
friend struct AccumulatorCaches::Cache;
friend class AccumulatorStack;
};
// Definitions of the network types
+3 -8
View File
@@ -25,7 +25,6 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <vector>
#include "../types.h"
#include "nnue_architecture.h"
@@ -48,7 +47,7 @@ template<IndexType Size>
struct alignas(CacheLineSize) Accumulator {
std::int16_t accumulation[COLOR_NB][Size];
std::int32_t psqtAccumulation[COLOR_NB][PSQTBuckets];
std::array<bool, COLOR_NB> computed;
std::array<bool, COLOR_NB> computed = {};
};
@@ -142,10 +141,6 @@ struct AccumulatorState {
class AccumulatorStack {
public:
AccumulatorStack() :
accumulators(MAX_PLY + 1),
size{1} {}
[[nodiscard]] const AccumulatorState& latest() const noexcept;
void reset() noexcept;
@@ -178,8 +173,8 @@ class AccumulatorStack {
const FeatureTransformer<Dimensions>& featureTransformer,
const std::size_t end) noexcept;
std::vector<AccumulatorState> accumulators;
std::size_t size;
std::array<AccumulatorState, MAX_PLY + 1> accumulators;
std::size_t size = 1;
};
} // namespace Stockfish::Eval::NNUE