Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2001:
[Freeciv-Dev] Re: Profiling Civserver again
Home

[Freeciv-Dev] Re: Profiling Civserver again

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Profiling Civserver again
From: Jason Dorje Short <jshort@xxxxxxxxxxxxx>
Date: Wed, 25 Jul 2001 02:38:56 -0400

Trent Piepho wrote:
> 
> On Tue, 24 Jul 2001, Ross W. Wetmore wrote:
> > 2)  TRUE, map and map_adjust_x() will need to be defined in all functions
> >     that call the macro, whereas they weren't for the function call.
> 
> Of course the function prototype for normalize_map_pos() is in the same header
> file that defines map_adjust_x(), so that shouldn't be a problem.
> 
> But really, you're just covering up the real inefficiency.  It would be more
> productive to figure out why map coordinates get normalized so many times, and
> reduce that number.

I draw your attention to the following lines from the gprof run:

[12]    20.4  100.19  102.49  159008         really_generate_warmap [12]
               38.41    0.00 797302800/948124931     normalize_map_pos
[32]

This says that of the 950 million times normalize_map_pos was called 800
million of them were in really_generate_warmap.  About 40% as much time
was spent in normalize_map_pos as was spent in really_generate_warmap()
itself.

In other words, the following line accounts for about 4% of all Freeciv
server CPU usage:
        http://www.freeciv.org/lxr/source/server/gotohand.c?v=cvs#L313

Aside from being astounding, this is totally unnecessary and can easily
be improved on.

With the attached patch, the use of normalize_map_pos is dropped and the
normalization is handled manually.  This could be improved on much more
- the normalization is still done for each of the 8 adjacent spots - but
it is more efficient than the function call or even a standard macro
would be.

jason
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.99
diff -u -r1.99 gotohand.c
--- server/gotohand.c   2001/06/29 19:39:06     1.99
+++ server/gotohand.c   2001/07/25 06:14:57
@@ -308,9 +308,9 @@
   while (get_from_mapqueue(&x, &y)) {
     ptile = map_get_tile(x, y);
     for (dir = 0; dir < 8; dir++) {
-      x1 = x + DIR_DX[dir];
+      x1 = (x + DIR_DX[dir] + map.xsize) % map.xsize;
       y1 = y + DIR_DY[dir];
-      if (!normalize_map_pos(&x1, &y1))
+      if (y1 < 0 || y1 >= map.ysize)
        continue;
 
       switch (move_type) {

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