Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] Re: (PR#12315) Slowness (fix)
Home

[Freeciv-Dev] Re: (PR#12315) Slowness (fix)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: chrisk@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#12315) Slowness (fix)
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sun, 6 Mar 2005 10:08:37 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12315 >

On Mon, 21 Feb 2005, Christian Knoke wrote:
> contains 6 living AI players, and a total of 366 cities and 968 units.
>
> It requires 18 seconds (real) to start on a 2 GHz machine (time from click
> on 'start' button until it is responsive).

This patch should speed it up. On my computer it went from 57 seconds to 8
:-)

However, there is a cost. If the AI's first 50 cities are very different
from its remaining cities, its selection of government may be rather
suboptimal (eg if its core 50 cities are unaffected by war, so it selects
Republic for waging war, making its remaining 200 cities suffer heavy
upkeep).

  - Per

Index: ai/aihand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v
retrieving revision 1.103
diff -u -r1.103 aihand.c
--- ai/aihand.c 5 Mar 2005 13:48:25 -0000       1.103
+++ ai/aihand.c 6 Mar 2005 18:03:27 -0000
@@ -64,6 +64,8 @@
 
 #define LOGLEVEL_TAX LOG_DEBUG
 
+#define MAX_CITIES_FOR_GOVT_EVAL 50
+
 /**************************************************************************
  handle spaceship related stuff
 **************************************************************************/
@@ -266,6 +268,8 @@
     government_iterate(gov) {
       int val = 0;
       int dist;
+      int samples = 0; /* only run through some cities and hope
+                        * they are representative */
 
       if (gov->index == game.government_when_anarchy) {
         continue; /* pointless */
@@ -275,13 +279,19 @@
        * this is a rather big CPU operation, we'd rather not. */
       check_player_government_rates(pplayer);
       city_list_iterate(pplayer->cities, acity) {
-        acity->ai.celebrate = FALSE;
-       /* This isn't strictly necessary since it's done in aaw. */
-        generic_city_refresh(acity, TRUE, NULL);
         auto_arrange_workers(acity);
+        samples++;
+        if (samples > MAX_CITIES_FOR_GOVT_EVAL) {
+          break;
+        }
       } city_list_iterate_end;
+      samples = 0;
       city_list_iterate(pplayer->cities, pcity) {
         val += ai_eval_calc_city(pcity, ai);
+        samples++;
+        if (samples > MAX_CITIES_FOR_GOVT_EVAL) {
+          break;
+        }
       } city_list_iterate_end;
 
       /* Bonuses for non-economic abilities. We increase val by

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