Skip to content

Commit

Permalink
Swap two loops in compute_max_stats_heuristics
Browse files Browse the repository at this point in the history
Profiling has shown city_tile_iterate to be expensive, with the
governors spending 20% of their time in it. They are used in a double
loop with output types. Swap the two loops to have the expensive one
outside, speeding up governors by about 15% in LTT.
  • Loading branch information
lmoureaux committed Jul 6, 2024
1 parent c645cd1 commit 569bacd
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions common/aicore/cm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,18 +1600,21 @@ static void compute_max_stats_heuristic(const struct cm_state *state,

output_type_iterate(stat_index)
{
int base = production[stat_index];
pcity->citizen_base[stat_index] = production[stat_index];
}

city_tile_iterate(city_map_radius_sq_get(pcity), pcenter, ptile)
{
if (is_free_worked(pcity, ptile)) {
base += city_tile_output(pcity, ptile, is_celebrating, stat_index);
city_tile_iterate(city_map_radius_sq_get(pcity), pcenter, ptile)
{
if (is_free_worked(pcity, ptile)) {
output_type_iterate(stat_index)
{
pcity->citizen_base[stat_index] +=
city_tile_output(pcity, ptile, is_celebrating, stat_index);
}
output_type_iterate_end;
}
city_tile_iterate_end;
pcity->citizen_base[stat_index] = base;
}
output_type_iterate_end;
city_tile_iterate_end;

set_city_production(pcity);
memcpy(production, pcity->prod, sizeof(pcity->prod));
Expand Down

0 comments on commit 569bacd

Please sign in to comment.