Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2005:
[Freeciv-Dev] (PR#11905) the new auto_arrange_workers is really slow
Home

[Freeciv-Dev] (PR#11905) the new auto_arrange_workers is really slow

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11905) the new auto_arrange_workers is really slow
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 12 Jan 2005 11:33:23 -0800
Reply-to: bugs@xxxxxxxxxxx

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

I think it's because of this query, which wasn't present for AI players 
before (only for non-AI players...which is just as bad but doesn't show 
up in autogames):

   if (!cmr.found_a_valid) {
     cmp.minimal_surplus[O_FOOD] = -(pcity->food_stock);
     cmp.minimal_surplus[O_TRADE] = -FC_INFINITY;
     cm_query_result(pcity, &cmp, &cmr);
   }

not only is this potentially an extra query, but it's really slow 
because the current CM doesn't do well with large negatives for a 
minimal food surplus.

These lines should probably be dropped entirely, from the dev and the 
stable branch.  The fallback immediately below it should be both safer 
and faster.

As a side note, it's impossible to have a negative trade surplus.

With the attached patch (for the dev branch) the CM runtime drops from 
50% to 30% of the server runtime.  This drops overall runtime by about 1/3.

-jason

? gmon.out
? gprof
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.293
diff -u -r1.293 cityturn.c
--- server/cityturn.c   12 Jan 2005 18:38:03 -0000      1.293
+++ server/cityturn.c   12 Jan 2005 19:31:43 -0000
@@ -242,21 +242,19 @@
   cm_query_result(pcity, &cmp, &cmr);
 
   if (!cmr.found_a_valid) {
-    /* Drop surpluses and try again. */
-    cmp.minimal_surplus[O_FOOD] = 0;
+    /* Drop surpluses and try again.  This allows us to starve but not to
+     * run short on shields.  Disorder is still not allowed (we'd rather
+     * shrink than go to disorder). */
+    cmp.minimal_surplus[O_FOOD] = MIN(pcity->surplus[O_FOOD], 0);
     cmp.minimal_surplus[O_SHIELD] = 0;
     cmp.minimal_surplus[O_GOLD] = -FC_INFINITY;
     cm_query_result(pcity, &cmp, &cmr);
   }
   if (!cmr.found_a_valid) {
-    cmp.minimal_surplus[O_FOOD] = -(pcity->food_stock);
-    cmp.minimal_surplus[O_TRADE] = -FC_INFINITY;
-    cm_query_result(pcity, &cmp, &cmr);
-  }
-  if (!cmr.found_a_valid) {
     /* Emergency management.  Get _some_ result.  This doesn't use
      * cm_init_emergency_parameter so we can keep the factors from
-     * above. */
+     * above.  At this point all minimums are dropped and disorder is
+     * allowed. */
     output_type_iterate(o) {
       cmp.minimal_surplus[o] = MIN(cmp.minimal_surplus[o],
                                   MIN(pcity->surplus[o], 0));
@@ -267,7 +265,7 @@
   }
   if (!cmr.found_a_valid) {
     /* Should never happen. */
-    CITY_LOG(LOG_DEBUG, pcity, "emergency management");
+    CITY_LOG(LOG_ERROR, pcity, "emergency management");
     cm_init_emergency_parameter(&cmp);
     cm_query_result(pcity, &cmp, &cmr);
   }

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