From 2ba47416cbdd5db2c7c79257072cd8675b61721f Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Mon, 1 Jan 2018 10:10:41 +0100 Subject: [PATCH] Explicitly zero TT upon resize. as discussed in issue #1349, the way pages are allocated with calloc might imply some overhead on first write. This overhead can be large and slow down the first search after a TT resize significantly, especially for large TT. Using an explicit clear of the TT on resize fixes this problem. Not implemented, but possibly useful for large TT, is to do this zero-ing using all search threads. Not only would this be faster, it could also lead to a more favorable memory allocation on numa systems with a first touch policy. No functional change. --- src/tt.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tt.cpp b/src/tt.cpp index a1ef4442..354ead87 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -41,7 +41,7 @@ void TranspositionTable::resize(size_t mbSize) { clusterCount = newClusterCount; free(mem); - mem = calloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1, 1); + mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1); if (!mem) { @@ -51,6 +51,7 @@ void TranspositionTable::resize(size_t mbSize) { } table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1)); + clear(); } -- 2.39.2