Przeglądaj źródła

reorder fields to shrink struct TerrainTile from 96 to 80 bytes

When I was playing a very large map, computer's turn took up to 2 minutes and that give me time to fire up perf and profile the code while waiting.

I noticed that 1.7% of time was spent in function CPathfinderHelper::getNeighbors and half of that on a single load from an array backing multi_array of TerrainTiles. That signals the CMap::terrain is too big to fit in CPU caches.

This patch reorders fields in TerrainTile struct, shrinking it from 96 bytes to 80 bytes and hopefully helping to keep more tiles in the cache and speeding things up a little bit.
K 1 rok temu
rodzic
commit
d3c198678c
1 zmienionych plików z 2 dodań i 2 usunięć
  1. 2 2
      lib/mapping/CMapDefines.h

+ 2 - 2
lib/mapping/CMapDefines.h

@@ -97,10 +97,10 @@ struct DLL_LINKAGE TerrainTile
 	bool hasFavorableWinds() const;
 	bool hasFavorableWinds() const;
 
 
 	const TerrainType * terType;
 	const TerrainType * terType;
-	ui8 terView;
 	const RiverType * riverType;
 	const RiverType * riverType;
-	ui8 riverDir;
 	const RoadType * roadType;
 	const RoadType * roadType;
+	ui8 terView;
+	ui8 riverDir;
 	ui8 roadDir;
 	ui8 roadDir;
 	/// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
 	/// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
 	///	7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favorable Winds effect
 	///	7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favorable Winds effect