Latest Posts

Topic: widelands and CPU usage

king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-10-01, 21:00

I've been checking the use of my laptop's resources to see if I could identify the cause of some slowness, and I've been fairly surprised by what I saw in widelands. I was playing a 300x300 map (no metal challenge, that i posted yesterday) with a game that had lasted 13 hours, and i noticed that widelands took over 30% of my CPU. That's understandable, big map, long game. But I went to do otjher stuff, and I paused the game, but it still consumed 30% of the CPU. I can understand that all the calculation for tree growth and road traffic and ware destinations would take a lot of processing, but when the game is paused? For the sake of experiment, I raised the speed to 10x, and the CPU usage increased to 35%. Not much. So, all those factors I mentioned before only make for a very small amount of the total CPU usage.

I was intrigued and tried some different stuff then. I opened the smallest map, crater, and the consumption is 15% now. I suspected it could have something to do with terrain animations, but crater has an area 20 times smaller than no metal challenge, so it can't be that either.

Last, I tried to open a new game in no metal challenge. The CPU usage this time was 15% or less. So, a new game takes less resources than an old one. But why is that?

There are two options. One, all the buildings are taking CPU. Two, CPU usage increases with time. Luckily, I found an old save on the same map where the game had lasted 4 and a half hours (but most buildings had already been completed), and I opened that, and the CPU usage stabilized around 20%. Bingo. An increase of 5% of my CPU every 4 hours, starting with 15%, would fit very well with 30% after 13 hours.

I already remarked long ago how long games tend to slow down as they take more and more of a pc's resources: https://wl.widelands.org/forum/topic/1589/ Ironically, I was in a no metal challenge also that time, because it's the only way to make games so long that they last tens of hours.

Anyway, I think there must be something wrong with the coding. If nothing else, there must be some room for optimization. It's not possible that the vast majority of CPU consumption of the game comes from passing time independently from what you actually do in the game. Or that the game keeps eating resources even when paused.

P.S. It wasn't widelands that slowed down my pc anyway; problem was reading from hard disk, and it was windows shit doing that.


Top Quote
einstein13
Avatar
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-10-01, 21:41

I've noticed the problem not only on Windows. face-wink.png Linux also make some "shit".

I used Linux to run Widelands self-compiled-dev version. After few hours of test (~30 hours of gametime) the problem was very, very significant.

I remember, that in the past, the most problematic were statistics. Opening statistics window used more than 50% of CPU. New version of Widelands makes it better, but problably not enough for very, very long games. I even tried to ask about that (https://wl.widelands.org/forum/topic/1589/?page=1#post-11680), but noone answered.


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-10-02, 00:56

seems pretty strange that statistics would require CPU. the way I see it, they should be a string of data, minute per minute, so they should occupy memory, but they should not require particular calculus.


Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-10-02, 18:08

by the way, i checked, and opening the statistics only increase CPU usage by a few %.


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 14:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2015-10-02, 18:57

I guess the question about the statistics here is how much of it is calculated on the fly, and how much of it is stored. I am not familiar with that part of the code. Also, plotting graphs takes more CPU than displaying text.

I think improving the performance is generally a good idea, but I personally don't have any practical experience whatsoever with profiling etc.


Busy indexing nil values

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-10-02, 19:40

when game is paused, gametime does not go, so neither AI neither any objects (production sites, workers) are doing nothing - I think.

Have you tried to reduce max fpx? This will reduce CPU use...

I believe this is issue of graphics...


Top Quote
einstein13
Avatar
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-10-02, 21:10

king_of_nowhere wrote:

by the way, i checked, and opening the statistics only increase CPU usage by a few %.

I remember that the major problem was with statistics for "full game". Calculations are pretty easy, but they probably were done every frame. That can be very RAM-usage. I guess that now it is better than before, but you can check whether displaying full game statistics are making difference?

But I am not saying that only statistics make CPU-usage! I remember that in the past it was bottleneck for the game. There is number of places where bottlenecks can be. (computer AI for example)


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-10-03, 15:44

Tibor wrote:

when game is paused, gametime does not go, so neither AI neither any objects (production sites, workers) are doing nothing - I think.

Have you tried to reduce max fpx? This will reduce CPU use...

I believe this is issue of graphics...

I tried to reduce the fps from 25 to 15, and there was no appreciable difference.

A few more strange things.

  • loading a long game takes much longer. I chronometered it, and I needed over two minutes to lload a 30 hours game. For longer games, it takes even more (my record was a 140-hours game, but I didn't measure the time then). There is no way this is connected to loading of sttistics or other data. The savegame file isn't that big anyway (1.5 megabytes). Unfortunately it would not accept an alt-tab when I am in loading screen, so I could not see the usage of resources during the loading.

  • closing a long game also take an unreasonable amount of time. In my case, when I clicked exit game, it took over one and a half minute before it went back to the main menu. What could be that for?

  • CPU usage may only become relevant when the game is reduced to icon. I can't see CPU usage when I have the game in fullscreen, but every time I pressed alt-tab to check on it, I found it at 12%, and it increased up to 35% in a few seconds. It sometimes goes down at 12% on its own for a second, but what are the chances that on reduciing to icon the game four consecutive times I always found those few seconds when it went to 12%? It's more likely the game takes more CPU when it is not in fullscreen, even though it doesn't seem to make sense.

I'm not an expert, but I would conclude there is some serious issue with the coding that is not related to anything obvious but causes the game to become slower and slower and take more resources with the passing of time.


Top Quote
Venatrix
Avatar
Joined: 2010-10-05, 19:31
Posts: 449
Ranking
Tribe Member
Location: Germany
Posted at: 2015-10-03, 20:09

If you want to check on the CPU usage all the time, why don’t you play windowed? Just to test it.


Two is the oddest prime.

Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 19:48
Posts: 2439
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2015-10-04, 10:51

king_of_nowhere wrote:

  • loading a long game takes much longer. I chronometered it, and I needed over two minutes to lload a 30 hours game. For longer games, it takes even more (my record was a 140-hours game, but I didn't measure the time then). There is no way this is connected to loading of sttistics or other data. The savegame file isn't that big anyway (1.5 megabytes). Unfortunately it would not accept an alt-tab when I am in loading screen, so I could not see the usage of resources during the loading.

You could start widelands from a terminal/console/prompt. In there will be the output of which part loads in which time. So you could compare the output with a short time game.


Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote