Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2003:
[Freeciv-Dev] Re: (PR#4381) some clean with get_map_tile(...) , get_map_
Home

[Freeciv-Dev] Re: (PR#4381) some clean with get_map_tile(...) , get_map_

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: bursig@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#4381) some clean with get_map_tile(...) , get_map_terrain(...), get_map_special(...) ...
From: "rwetmore@xxxxxxxxxxxx" <rwetmore@xxxxxxxxxxxx>
Date: Tue, 10 Jun 2003 05:28:08 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This is a general performance problem that arises from using map coordinates
everywhere by default.

There are several partial remedies of a more systemmic nature.

1)  The most abused reference accessors should be coded as nested macros
     where the inner macros do the basic 2-D to linear convert. Doing this
     ensures that the compiler can recognize common code because it really
     is identical across all different accessors - it helps a lot. The inner
     forms can also be tuned to make sure they use as few global variables
     and such as possible, which thwarts optimization.

2)  Developers should explicitly cache tile pointers or linear addresses
     in local variables in inner loops and code efficiently so that not all
     the load is on the optimizer. There should always be two forms, a 2-D
     and a tile-based or linear for key lookups which follows naturally from
     the above nesting. Thus if one computes and caches a linear address, one
     can easily switch to using the linear form in all subsequent cases, even
     with different accessors.

3)  In general, do index computations with local variables. The simple act
     of loading a global variable into a local tells the compiler a lot about
     how it and all values computed from it can be cached vs recomputed. One
     hidden global in such a computation kills the optimization. Use of const
     modifiers can partially help with some globals like map.xsize.

4)  In general algorithms should be refactored to understand basic 2-D
     loop character and deal with it efficiently, rather than hiding or
     ignoring it through misplaced assumptions of the simplicity or
     equivalence of 2-D coordinate representations. This is not a licence
     for massive premature optimization, but just a recognition of good
     programming priniciples in developing algorithms.

Cheers,
RossW
=====

Rafa³ Bursig wrote:
> Hi All
> 
> Yesterday I was look into new veteran code and I found that many times 
> in code (not only in veteran code) are call get_map_terrain(...) and 
> get_map_special(...) , map_has_special(...) , etc , even if there is 
> struct tile declared and defined. IMHO this is resource waste when we 
> calc. map tile each time when we want check terrain, special, city, 
> etc, many time in one fuction call.
> 
> I attach some fix code but this don't tuch all cases and someone could 
> check it becouse large part of it I made yesterday late night ( or 
> early morning :) and something I may be corrupt.
> 
> Rafal




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