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 53d4abf
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions common/aicore/cm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,20 +1598,21 @@ static void compute_max_stats_heuristic(const struct cm_state *state,
struct tile *pcenter = city_tile(pcity);
bool is_celebrating = base_city_celebrating(pcity);

output_type_iterate(stat_index)
city_tile_iterate(city_map_radius_sq_get(pcity), pcenter, ptile)
{
int base = production[stat_index];

city_tile_iterate(city_map_radius_sq_get(pcity), pcenter, ptile)
output_type_iterate(stat_index)
{
int base = production[stat_index];

if (is_free_worked(pcity, ptile)) {
base += city_tile_output(pcity, ptile, is_celebrating, stat_index);
}

pcity->citizen_base[stat_index] = base;
}
city_tile_iterate_end;
pcity->citizen_base[stat_index] = base;
output_type_iterate_end;
}
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 53d4abf

Please sign in to comment.