Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: Profile.
Home

[Freeciv-Dev] Re: Profile.

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gaute B Strokkenes <gs234@xxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Profile.
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 26 Sep 2001 18:28:49 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Wed, Sep 26, 2001 at 10:59:49AM +0200, Raimar Falke wrote:
> On Wed, Sep 26, 2001 at 03:40:19AM +0200, Gaute B Strokkenes wrote:
> > 
> > I ran an all-AI game with a CVS snapshot from a couple of days back,
> > with the below (abbreviated) results.  Interested parties can get the
> > whole thing from <http://www.srcf.ucam.org/~gs234/gmon.txt.bz2>.
> > 
> > This largely confirms what I've said before; normalize_map_pos() takes
> > a lot of time and is_real_tile() should definitely be replaced with a
> > macro.
> 
> There is hope! After the removal of the DIR_DX array I made some
> changes to catch any un-real map positions. There were none. So I
> changed it to catch any non-normal(ized) map accesses. They came from
> lines such as:
> 
>   enum tile_special_type spec_t=map_get_special(pcity->x+x-2, pcity->y+y-2);
>   enum tile_terrain_type tile_t=map_get_terrain(pcity->x+x-2, pcity->y+y-2);
> 
> The proposed patch would get rid of these. Although I haven't checked
> I'm sure that there are none or only a very few non-normal(ized) map
> accesses left. So we can in theory remove a lot of the is_real_tile
> and normalize_map_pos calls in map_get_tile and co. However for the
> ability to check this in the long run I would like to propose the
> following:
> 
> #define CHECK_MAP_POS(x,y) do{\
>     int dx = x, dy = y; \
>     assert(normalize_map_pos(&dx, &dy)); \
>     assert(x == dx && y == dy); \
>   } while(0)
> 
> So map_get_tile would be like:
> 
> struct tile *map_get_tile(int x, int y)
> {
>   CHECK_MAP_POS(x,y);
> 
>   return map.tiles + map_inx(x, y);
> }
> 
> CHECK_MAP_POS can now check for 
>  - un-real map position or for
>  - non-normal(ized) map positions or
>  - can be a noop
> 
> This can be tied to NDEBUG or something other.

Patch to do this is attached. It turns out that there really one
access with un-normal(ized) map positions left.

Profile data:

CHECK_MAP_POS doing full checks:

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 13.06     16.93    16.93 333536324     0.00     0.00  normalize_map_pos
  9.75     29.56    12.63    27300     0.46     0.77  really_generate_warmap
  6.06     37.42     7.86 333553771     0.00     0.00  is_real_tile
  4.12     42.76     5.34 105677697     0.00     0.00  tech_exists
  4.04     47.99     5.23 86999744     0.00     0.00  map_get_tile
  3.33     52.30     4.31 49607029     0.00     0.00  map_get_terrain
  2.40     55.41     3.11 95909197     0.00     0.00  get_invention
  1.89     57.86     2.45 24840101     0.00     0.00  base_local_city_map_to_map
  1.57     59.89     2.03  1006465     0.00     0.01  road_bonus
  1.56     61.91     2.02 22976603     0.00     0.00  map_get_city
  1.44     63.78     1.87 46484826     0.00     0.00  unit_type_flag
  1.36     65.54     1.76 18569271     0.00     0.00  map_get_special
  1.32     67.25     1.71 16671253     0.00     0.00  map_get_continent
  1.17     68.77     1.52   623367     0.00     0.01  
player_knows_techs_with_flag
  1.16     70.27     1.50 15001555     0.00     0.00  get_from_mapqueue
  1.15     71.76     1.49     1558     0.96     6.69  ai_manage_explorer
  1.13     73.22     1.46 36336394     0.00     0.00  is_valid_city_coords
  1.13     74.68     1.46 25211331     0.00     0.00  improvement_exists
  1.12     76.13     1.45      302     4.80    12.52  check_fow
  1.10     77.56     1.43 35899901     0.00     0.00  find_genlist_position
  1.07     78.95     1.39 35898163     0.00     0.00  genlist_iterator_init

CHECK_MAP_POS is a noop:

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 11.82     12.64    12.64    27300     0.46     0.66  really_generate_warmap
  5.59     18.62     5.98 107829491     0.00     0.00  normalize_map_pos
  4.95     23.91     5.29 105677697     0.00     0.00  tech_exists
  3.02     27.14     3.23 95909197     0.00     0.00  get_invention
  2.68     30.00     2.86 49607029     0.00     0.00  map_get_terrain
  2.49     32.66     2.66 107846938     0.00     0.00  is_real_tile
  2.41     35.24     2.58 86999744     0.00     0.00  map_get_tile
  2.16     37.55     2.31 24840101     0.00     0.00  base_local_city_map_to_map
  1.89     39.57     2.02  1006465     0.00     0.00  road_bonus
  1.85     41.55     1.98 46484826     0.00     0.00  unit_type_flag
  1.64     43.30     1.75 36336394     0.00     0.00  is_valid_city_coords
  1.64     45.05     1.75   623367     0.00     0.01  
player_knows_techs_with_flag
  1.51     46.66     1.61 35899901     0.00     0.00  find_genlist_position
  1.47     48.23     1.57     1558     1.01     4.87  ai_manage_explorer
  1.45     49.78     1.55 14967809     0.00     0.00  add_to_mapqueue
  1.33     51.20     1.42 15001555     0.00     0.00  get_from_mapqueue
  1.32     52.61     1.41 25211331     0.00     0.00  improvement_exists
  1.28     53.98     1.37      302     4.54     7.67  check_fow
  1.21     55.27     1.29 35898163     0.00     0.00  genlist_iterator_init
  1.18     56.53     1.26 22976603     0.00     0.00  map_get_city
  1.15     57.76     1.23     7683     0.16     1.88  evaluate_improvements
  1.05     58.88     1.12  2221817     0.00     0.00  amortize
  1.01     59.96     1.08 18569271     0.00     0.00  map_get_special

The following data is also for CHECK_MAP_POS been a noop:

                0.00    0.00       4/107829491     make_fair [583]
                0.00    0.00      20/107829491     make_swamps [702]
                0.00    0.00      38/107829491     is_at_coast [806]
                0.00    0.00      53/107829491     find_empty_tile_nearby [786]
                0.00    0.00      72/107829491     make_desert [775]
                0.00    0.00     128/107829491     reset_move_costs [617]
                0.00    0.00     160/107829491     make_forest [681]
                0.00    0.00     208/107829491     river_blockmark [767]
                0.00    0.00     210/107829491     emergency_reallocate_workers 
[455]
                0.00    0.00     216/107829491     ai_manage_barbarian_leader 
[382]
                0.00    0.00     231/107829491     river_test_blocked [760]
                0.00    0.00     273/107829491     transfer_city [335]
                0.00    0.00     273/107829491     
give_citymap_from_player_to_player [477]
                0.00    0.00     378/107829491     map_fog_pseudo_city_area 
[531]
                0.00    0.00    1091/107829491     is_near_land [677]
                0.00    0.00    1329/107829491     unit_can_be_retired [621]
                0.00    0.00    1408/107829491     is_tiny_island [635]
                0.00    0.00    1566/107829491     ai_military_gothere [112]
                0.00    0.00    1764/107829491     
really_give_tile_info_from_player_to_player [501]
                0.00    0.00    2016/107829491     adjacent_river_tiles4 [640]
                0.00    0.00    2037/107829491     ai_do_build_city [227]
                0.00    0.00    2048/107829491     initialize_move_costs [411]
                0.00    0.00    2110/107829491     show_area [430]
                0.00    0.00    2310/107829491     remove_city [529]
                0.00    0.00    2331/107829491     map_unfog_pseudo_city_area 
[362]
                0.00    0.00    2770/107829491     is_special_close [651]
                0.00    0.00    2947/107829491     goto_zoc_ok [125]
                0.00    0.00    3216/107829491     adjacent_terrain_tiles4 [632]
                0.00    0.00    3426/107829491     is_hut_close [643]
                0.00    0.00    3505/107829491     is_my_turn [577]
                0.00    0.00    3807/107829491     reinforcements_value [605]
                0.00    0.00    3952/107829491     make_river [593]
                0.00    0.00    4488/107829491     can_channel_land [475]
                0.00    0.00    5951/107829491     do_unit_goto [32]
                0.00    0.00    6276/107829491     terrain_is_clean [585]
                0.00    0.00    7140/107829491     server_remove_unit [318]
                0.00    0.00    7592/107829491     test_unit_move_to_tile [379]
                0.00    0.00    9996/107829491     really_show_area [460]
                0.00    0.00   10215/107829491     assign_continent_flood [578]
                0.00    0.00   10290/107829491     create_unit_full [283]
                0.00    0.00   19884/107829491     check_coords [574]
                0.00    0.00   25785/107829491     setup_isledata [450]
                0.00    0.00   44670/107829491     is_special_near_tile [528]
                0.00    0.00   45522/107829491     remove_city_from_minimap 
[520]
                0.00    0.00   53622/107829491     add_city_to_minimap [511]
                0.00    0.00   73419/107829491     fog_area [272]
                0.00    0.00   73652/107829491     find_a_direction [317]
                0.00    0.00   74934/107829491     maybe_make_first_contact 
[373]
                0.00    0.00   84040/107829491     find_the_shortest_path [41]
                0.01    0.00  104517/107829491     ai_military_findvictim [146]
                0.01    0.00  104762/107829491     unfog_area <cycle 2> [138]
                0.01    0.00  106956/107829491     reveal_pending_seen <cycle 
2> [375]
                0.01    0.00  141687/107829491     road_trade [329]
                0.01    0.00  160377/107829491     build_landarea_map_new [322]
                0.01    0.00  164596/107829491     find_beachhead [280]
                0.01    0.00  182096/107829491     
is_wet_or_is_wet_cardinal_around [324]
                0.01    0.01  228249/107829491     ocean_workers [282]
                0.01    0.01  257626/107829491     tile_is_accessible [73]
                0.02    0.01  324450/107829491     
handle_unit_move_consequences [94]
                0.02    0.01  333837/107829491     worker_loop <cycle 1> [34]
                0.02    0.01  338003/107829491     enemies_at [253]
                0.02    0.01  344025/107829491     send_NODRAW_tiles [285]
                0.03    0.01  465713/107829491     can_reclaim_ocean [269]
                0.03    0.01  577416/107829491     really_unfog_area [158]
                0.03    0.01  605344/107829491     assign_region [255]
                0.04    0.02  649974/107829491     is_water_adjacent_to_tile 
[248]
                0.04    0.02  805070/107829491     wakeup_neighbor_sentries 
[221]
                0.05    0.02  950760/107829491     build_landarea_map_expand 
[242]
                0.05    0.02  989843/107829491     is_coastline [237]
                0.08    0.04 1471089/107829491     base_map_to_local_city_map 
[214]
                0.11    0.05 1907514/107829491     city_desirability [45]
                0.11    0.05 2016295/107829491     invasion_funct [171]
                0.12    0.05 2199057/107829491     evaluate_improvements [15]
                0.14    0.06 2575587/107829491     server_set_tile_city <cycle 
1> [110]
                0.17    0.07 2988744/107829491     really_generate_warmap [12]
                0.17    0.08 3084930/107829491     check_map [105]
                0.22    0.10 4037889/107829491     is_tiles_adjacent [164]
                0.23    0.10 4064307/107829491     evaluate_city_building [14]
                0.25    0.11 4438530/107829491     
city_reinforcements_cost_and_value [102]
                0.26    0.12 4719033/107829491     goto_is_sane [84]
                0.30    0.13 5397132/107829491     city_can_be_built_here [118]
                0.34    0.15 6190260/107829491     is_terrain_near_tile [103]
                0.38    0.17 6789675/107829491     is_square_threatened [80]
                0.39    0.17 7072016/107829491     
city_exists_within_city_radius [68]
                0.49    0.22 8804108/107829491     is_my_zoc [59]
                0.51    0.23 9267697/107829491     ai_manage_explorer [26]
                0.51    0.23 9282909/107829491     local_city_map_to_map [67]
                0.73    0.32 13084045/107829491     road_bonus [43]
[21]     8.1    5.98    2.66 107829491         normalize_map_pos [21]
                2.66    0.00 107829491/107846938     is_real_tile [64]
-----------------------------------------------
                2.02    2.29 1006465/1006465     evaluate_improvements [15]
[43]     4.0    2.02    2.29 1006465         road_bonus [43]
                0.73    0.32 13084045/107829491     normalize_map_pos [21]
                0.39    0.49 10964389/35898163     genlist_iterator_init [58]
                0.36    0.00 12054808/86999744     map_get_tile [66]
-----------------------------------------------
                0.00    0.00     210/24840101     emergency_reallocate_workers 
[455]
                0.00    0.00     273/24840101     transfer_city [335]
                0.00    0.00     273/24840101     
give_citymap_from_player_to_player [477]
                0.00    0.00     378/24840101     map_fog_pseudo_city_area [531]
                0.00    0.00    1764/24840101     
really_give_tile_info_from_player_to_player [501]
                0.00    0.00    2037/24840101     ai_do_build_city [227]
                0.00    0.00    2310/24840101     remove_city [529]
                0.00    0.00    2331/24840101     map_unfog_pseudo_city_area 
[362]
                0.00    0.00    7140/24840101     server_remove_unit [318]
                0.00    0.00    9996/24840101     really_show_area [460]
                0.00    0.00   10290/24840101     create_unit_full [283]
                0.01    0.01  141687/24840101     road_trade [329]
                0.01    0.01  160377/24840101     build_landarea_map_new [322]
                0.02    0.01  228249/24840101     ocean_workers [282]
                0.03    0.02  324450/24840101     handle_unit_move_consequences 
[94]
                0.03    0.02  333837/24840101     worker_loop <cycle 1> [34]
                0.05    0.03  577416/24840101     really_unfog_area [158]
                0.18    0.09 1907514/24840101     city_desirability [45]
                0.20    0.11 2199057/24840101     evaluate_improvements [15]
                0.24    0.12 2575587/24840101     server_set_tile_city <cycle 
1> [110]
                0.66    0.34 7072016/24840101     
city_exists_within_city_radius [68]
                0.86    0.45 9282909/24840101     local_city_map_to_map [67]
[50]     3.3    2.31    1.20 24840101         base_local_city_map_to_map [50]
                1.20    0.00 24840101/36336394     is_valid_city_coords [85]
-----------------------------------------------
                0.00    0.00   17447/107846938     check_units [391]
                2.66    0.00 107829491/107846938     normalize_map_pos [21]
[64]     2.5    2.66    0.00 107846938         is_real_tile [64]
-----------------------------------------------
                0.00    0.02   79282/9282909     city_can_work_tile [321]
                0.01    0.03  122647/9282909     server_set_tile_city <cycle 1> 
[110]
                0.01    0.03  122752/9282909     set_worker_city [353]
                0.01    0.03  144018/9282909     ai_calc_pollution [350]
                0.01    0.03  144018/9282909     ai_calc_fallout [308]
                0.01    0.03  144018/9282909     ai_calc_irrigate [178]
                0.01    0.03  144018/9282909     ai_calc_mine [279]
                0.01    0.03  144018/9282909     ai_calc_transform [216]
                0.01    0.03  144018/9282909     ai_calc_road [168]
                0.01    0.03  144018/9282909     ai_calc_railroad [124]
                0.01    0.06  279405/9282909     check_cities [162]
                0.12    0.51 2306499/9282909     city_get_trade_tile [56]
                0.13    0.58 2601326/9282909     city_get_food_tile [39]
                0.14    0.61 2762872/9282909     city_get_shields_tile [35]
[67]     2.4    0.48    2.05 9282909         local_city_map_to_map [67]
                0.86    0.45 9282909/24840101     base_local_city_map_to_map 
[50]
                0.51    0.23 9282909/107829491     normalize_map_pos [21]
-----------------------------------------------
                0.00    0.00    2450/36336394     create_city [258]
                0.00    0.00   46001/36336394     server_remove_worker_city [47]
                0.00    0.00   46412/36336394     server_set_worker_city <cycle 
1> [517]
                0.00    0.00   77224/36336394     update_city_tile_status 
<cycle 1> [289]
                0.01    0.00  110545/36336394     is_worker_here [438]
                0.01    0.00  122647/36336394     server_set_tile_city <cycle 
1> [110]
                0.53    0.00 11091014/36336394     get_worker_city [109]
                1.20    0.00 24840101/36336394     base_local_city_map_to_map 
[50]
[85]     1.6    1.75    0.00 36336394         is_valid_city_coords [85]
-----------------------------------------------
                0.00    0.00      10/133881      emergency_reallocate_workers 
[455]
                0.00    0.03   14698/133881      update_city_tile_status_map 
[108]
                0.00    0.10   56647/133881      check_cities [162]
                0.00    0.12   62526/133881      server_set_tile_city <cycle 1> 
[110]
[210]    0.2    0.01    0.25  133881         map_to_local_city_map [210]
                0.13    0.12  133881/133881      base_map_to_local_city_map 
[214]
-----------------------------------------------
                0.13    0.12  133881/133881      map_to_local_city_map [210]
[214]    0.2    0.13    0.12  133881         base_map_to_local_city_map [214]
                0.08    0.04 1471089/107829491     normalize_map_pos [21]
-----------------------------------------------

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Python is executable pseudocode. Perl is executable line noise"
    -- Bruce Eckel

Attachment: check_map_pos1.diff
Description: Text document


[Prev in Thread] Current Thread [Next in Thread]