memory prefetching (#4224)

This commit is contained in:
2025-07-01 19:13:15 -07:00
committed by GitHub
parent 2ecc40be6d
commit 34e43d3ce7
@@ -140,8 +140,13 @@ void ActionPointDistances::PopulateOne(
const Coords& currentCoords = indexToCoords[currentIndex];
visited[currentIndex] = true;
for (const std::array<int, 6>& neighbors = adjacencyTable[currentIndex];
int adjacentIndex : neighbors) {
// Prefetch terrain data for all neighbors to reduce memory stalls
const std::array<int, 6>& neighbors = adjacencyTable[currentIndex];
for (int i = 0; i < 6 && neighbors[i] != -1; i++) {
__builtin_prefetch(hexMap->terrain()->Get(neighbors[i]), 0, 3);
}
for (int adjacentIndex : neighbors) {
if (adjacentIndex == -1) break; // End of valid neighbors
if (visited[adjacentIndex]) continue;
@@ -168,6 +173,11 @@ void ActionPointDistances::PopulateOne(
return from.from == currentCoords;
});
if (entry != braveWaterPossibleCoords->details.end()) {
// Prefetch terrain data for water braving targets
for (const auto braveIndex : entry->to.indexIterator()) {
__builtin_prefetch(hexMap->terrain()->Get(braveIndex), 0, 3);
}
for (const auto braveIndex : entry->to.indexIterator()) {
if (visited[braveIndex]) continue;