Merge lp:~widelands-dev/widelands/bug-1786613-10s-return-skipped into lp:widelands

Proposed by Toni Förster
Status: Superseded
Proposed branch: lp:~widelands-dev/widelands/bug-1786613-10s-return-skipped
Merge into: lp:widelands
Diff against target: 33 lines (+9/-7)
1 file modified
src/logic/map_objects/tribes/productionsite.cc (+9/-7)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1786613-10s-return-skipped
Reviewer Review Type Date Requested Status
hessenfarmer Pending
Review via email: mp+353437@code.launchpad.net

This proposal supersedes a proposal from 2018-08-13.

This proposal has been superseded by a proposal from 2018-08-20.

Commit message

check for whether the program name is work or not.

Description of the change

I went a different route now. I did some logging and I figured out that the program is only labeled "work" when it calls other programs. Checking for the program name would solve this. there is one catch though. The main work program in the lua files should call a sub program to make this work. this is the case for e.g. Farms, Shipyard, Metalworkshop, etc. There only the unconditioned "return=skipped" needs to be removed.

Productionssites that only have work as a program need to be modified. E.g. the barbarians bakery currently looks like this:

   programs = {
      work = {
         -- TRANSLATORS: Completed/Skipped/Did not start baking bread because ...
         descname = pgettext("barbarians_building", "baking pitta bread"),
         actions = {
            "sleep=20000",
            "return=skipped unless economy needs barbarians_bread",
            "consume=water:3 wheat:3",
            "animate=working 20000",
            "produce=barbarians_bread",
            "animate=working 20000",
            "produce=barbarians_bread"
         }
      },
   },

Should then look like this:

   programs = {
      work = {
         -- TRANSLATORS: Completed/Skipped/Did not start baking bread because ...
         descname = _"working",
         actions = {
            "call=bake_bread",
         }
      },
      bake_bread = {
         descname = pgettext("barbarians_building", "baking pitta bread"),
         actions = {
            "sleep=20000",
            "return=skipped unless economy needs barbarians_bread",
            "consume=water:3 wheat:3",
            "animate=working 20000",
            "produce=barbarians_bread",
            "animate=working 20000",
            "produce=barbarians_bread"
         }
      },
   },

This of course needs to be done for all other buildings as well. It would also unify the way production programs are called. Work then would always call the "sub-programs" for all buildings. Not only the ones that produce only one ware or have the working routine split for other reasons.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote : Posted in a previous version of this proposal

Continuous integration builds have changed state:

Travis build 3782. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/415390227.
Appveyor build 3581. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1786613_10s_return_skipped-3581.

Revision history for this message
hessenfarmer (stephan-lutz) wrote : Posted in a previous version of this proposal

Ok I tested this with different timings.
My machine is a Core 2 Duo T7500 @ 2,2 Ghz with 4 GB RAM.
My setup was
map: the nile
8 AI players 2 of each tribe
Let the game run for 4:50 hours
saved and loaded with every config.

results were:
original timing: around 30% cpu usage in task manager, peaks up to 45%
10 ms timing: around 33% with more and higher peaks up to 60%
100 ms timing: around 32% less peaks than 10s up to 50%
500 ms timing: around 30 to 31 % peaks up to 50% but not much frequent.

So I would propose to have a value of 500 to 1000ms as compromise to ensure minimal effect on performance.

review: Needs Fixing
Revision history for this message
hessenfarmer (stephan-lutz) wrote : Posted in a previous version of this proposal

Looks good from my side now.
Would be good though if somebody with an underpowered machine would confirm minimal effect on performance

review: Approve
Revision history for this message
Toni Förster (stonerl) wrote : Posted in a previous version of this proposal

> Looks good from my side now.
> Would be good though if somebody with an underpowered machine would confirm
> minimal effect on performance

Do you think it gets much more underpowered. Your processor is basically the same as mine. Just a few MHz slower. The only difference is RAM.

Revision history for this message
ypopezios (ypopezios) wrote : Posted in a previous version of this proposal

In principle, if I was given a range to compromise with, I would go the conservative route and pick the edge of the range which is closer to the previous value. In this case, the given range is 500 to 1000ms, the previous value is 10000ms, so I would go with 1000ms.

Having said that, in my eyes an arbitrary value gets replaced by another arbitrary value. More tests of that kind won't make that value any less arbitrary. Therefore, I would comment this code for redesign in a future build.

Revision history for this message
hessenfarmer (stephan-lutz) wrote : Posted in a previous version of this proposal

@ypopezios: In principle you are right. It is somewhat arbitrary or you might say it is try and error. On the other hand I don't know how to handle this in a different way, cause more frequent calls of the working programs will always consume more processing power. so the value of 500 to 1000ms was chosen due to the consumed processing power on my machine while knowing the kind of measurement had some big uncertainties. Therefore I asked to test his issue on an even more underpowered system. For my understanding the more underpowered a testsystem would be the more visible would be the effect of this change.
@Toni Förster:
I was thinking to have this tested on a netbook or similar. As we support 1024x600 resolution we should support the processing power of those configs as well.

Revision history for this message
bunnybot (widelandsofficial) wrote : Posted in a previous version of this proposal

Continuous integration builds have changed state:

Travis build 3791. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/415624736.
Appveyor build 3590. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1786613_500ms_return_skipped-3590.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3782. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/415390227.
Appveyor build 3581. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1786613_10s_return_skipped-3581.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/map_objects/tribes/productionsite.cc'
2--- src/logic/map_objects/tribes/productionsite.cc 2018-06-19 08:52:49 +0000
3+++ src/logic/map_objects/tribes/productionsite.cc 2018-08-20 16:49:32 +0000
4@@ -920,7 +920,7 @@
5 stack_.pop_back();
6 if (!stack_.empty())
7 top_state().phase = result;
8-
9+
10 switch (result) {
11 case Failed:
12 statistics_.erase(statistics_.begin(), statistics_.begin() + 1);
13@@ -929,12 +929,14 @@
14 crude_percent_ = crude_percent_ * 8 / 10;
15 break;
16 case Completed:
17- skipped_programs_.erase(program_name);
18- statistics_.erase(statistics_.begin(), statistics_.begin() + 1);
19- statistics_.push_back(true);
20- train_workers(game);
21- crude_percent_ = crude_percent_ * 8 / 10 + 1000000 * 2 / 10;
22- calc_statistics();
23+ if (program_name.compare("work") != 0) {
24+ skipped_programs_.erase(program_name);
25+ statistics_.erase(statistics_.begin(), statistics_.begin() + 1);
26+ statistics_.push_back(true);
27+ train_workers(game);
28+ crude_percent_ = crude_percent_ * 8 / 10 + 1000000 * 2 / 10;
29+ calc_statistics();
30+ }
31 break;
32 case Skipped:
33 skipped_programs_[program_name] = game.get_gametime();

Subscribers

People subscribed via source and target branches

to status/vote changes: