High CPU and memory use

I’m not sure if it’s a bug or just normal feature related to flash and Adobe Air, but recently game starts lagging so much that it makes me wonder why so much.
My PC isn’t brand new, but c’mon, I believe that this game don’t have requirements like The Witcher or something similar…

The first thing that catch my eye was CPU usage, just after starting the game it rises to 50% and stays at that level all the time (even on title screen).
Also Memory usage jumps up to almost 200MB just after start the game and after loading save game or starting a new game it doubles! (so over 400MB).

game version: 0.8.6
operating system: WinXP SP3
HW: AMD Athlon 64 X2, Dual-Core TK-55 1,8GHz; 2GB RAM; NVidia GeForce 8400M G (512MB)

I check also on my older PC and got even worst results… Especially in CPU usage… I just start the game takes 95% of CPU usege (I couldn’t open anything new even program to save catched screen shot till I close the game).
OS: WinXP SP2
HW: AMD Sempron 2800+ (2Ghz); 1GB RAM; ATI Radeon 9550 128MB

As I mentioned I’m not very familiar with flash and Adobe Air, and I’m not sure if it is some kind of issue or not, but those values are a too high to me and they make playing this great game close to impossible on older computers.

I found and fixed this memory leak recently. This will hopefully be fixed in the next patch, coming out monday :slight_smile:

Yeah, I got memory usage up to 1.7 gigabytes a few days ago. It actually made my machine chug, which was… surprising.

I download the update, spend some time playing and for time to time game lags…

so I open Task Manager and well…
I still have high CPU and Memory usage… (around 55% of CPU and 450-500MB in Memory)
it rises to this values just after starting the new game or loading save file… and keeps till I close the game completely.

Hmmm, well that stinks. I’ll keep looking into it and see if I can optimize further. It’s definitely better than the last build, but it obviously still needs work. Any screen in particular causing problems? Also, does the memory keep marching upwards or does it plateau?

One problem we might have is the game is relying on a LOT on embedded media files, which might all be loaded into memory at startup. Eventually I plan to move to loose data files, which should hopefully help the problem, but might be over a month or so away in terms of patch scheduling.

well… CPU usage is on more or less the same level all the time (it changes from 45% to 65%), on party screen and during defend is a bit more, on map less, average is around 55% for my processor.

Memory usage jumps to 200MB just after starting the game (on title screen), after I load the game or choose to start new one it rises to 450 and stays on that level most of time, when I go to party screen (and make some clicks there) it raises a bit (I’ve got close 600MB max - for a short time), but after leaving that screen it returns to around 450MB and stay on that level till I completely close the game (quiting to Title screen) don’t change anything in Memory use…

I hope today I will have a bit more time so I can check it also on my other PC where playing was close to impossible…

edit:
playing on my older PC is almost impossible, game takes so much CPU and Memory, that it looks more like slide-show than a game, not mentioning response time…
I realize that memory use was increasing during defend by small amount with appearance of every new enemy (or maybe every attack my defenders made or maybe both), after stage ends it drops down to level lower level but not so low as before defense (if before stage it was 440MB, then after playing a level it drops down to 445MB, after next one it was 460MB and after third round go to 500MB…)

The surprising thing was that I accidentally minimize game to “Task bar” and although CPU usage didn’t change, Memory use drops down to 45MB!
after resuming and playing another round of defense on the same stage as before it rise to 250MB (and then with every replay start rising again).

Lars, already reported this through email, you can reproduce the leak simply by switching between the Party screen and the map. Made you a video, let me know if you want the original AVI.

While viewing the map, I’ve observed the following:

  1. Whereven I minimize the window, memory usage drops to just above 66M. No matter whether it remains minimized or whether I restore it (which eats abut 3M immediately), CPU usage is fluctuating between 40 and 60% of CPU, but when observing memory usage, it increases by some 100-150k every second, quite reliably. I haven’t had the patience to leave it running for a really long period of time yet, to see if there’s a limit…

Further observation - after it reached some 81M, it suddely jumped to 200M - but after some time it resumed in the gradual increase, so I can only assume that whatever kept allocating more memory just at some stage took a huge bite and kept filling it at the steady pace it otherwise showed. Surprisingly, some time later (I wasn’t watching every minute, but it was after it crept to at least 250M, it fell back to 203M. Just for the record, restore window again added some 3 megs and minimize brought it back to 65Megs.

Next try, party screen. Behaviour is similar, but the steps at which memory is eaten are much higher, about 300k per second. minimizing again releases the memory.

On title screen, the leag is about 32k per seconds.

Also, there’s a big difference in memory usage on title screen depending on whether the game has just started (about 13M when minimized) and when it was played and quit (about 66M, which I therefore figure is the footprint of various stuff that is allocated once when used).

In battle screen (paused at beginning of the battle) no leak occurs. quitting battle and going back to the map, again the 100k/s leak happens, reliably.

Cool, this is helpful. We’ll try to drill down what’s getting left behind next time I do a profiling-crunch and hopefully version 0.9.1 can have some improvements for this.

For version 0.8.9, I am having memory leak over time (about 120 kb/sec) while viewing the map (at least). It seems to be a rendering issue, but not sure.

There’s a world of difference between memory use and memory leak. None of those numbers sound outrageous for something written at such a high level, and you’d probably see them fall off if things got tight or something happened to trigger garbage collection.

edit: To be snide, the extra memory is probably being used to store the 6 miles of whitespace after every “W” in the character name/stat display font… wtf is up with that? :twisted: “Wendel” ends up looking like “W endel”

I somehow doubt any kind of memory needs to be allocated when the program is merely waiting for user input.
The game takes up less than 75 megs of disk space and then goes up to 1.5 gigs of ram in half an hour of use.
If it’s not a memory leak, then I think Lars should be awarded a Fields medal for his new data compression algorithm that achieves 2000% efficiency.
Also, I have no idea wtf Adobe’s doing behind the scenes when a flash game brings a computer that can run 3D games to its knees. I guess they don’t use hardware acceleration or something?

— Begin quote from "JorgeLima"

I somehow doubt any kind of memory needs to be allocated when the program is merely waiting for user input.

— End quote

A program doesn’t wait for anything, it’s a collection of ones and ohs.

“Input”… to put in… to put in what? Nothing, we’re merely waiting. Huh? Yeah, once it gets here we’re just going to stare at our fingernails and look pissed. What? I don’t know, some guy on the internet suggested it.

— Begin quote from ____

The game takes up less than 75 megs of disk space and then goes up to 1.5 gigs of ram in half an hour of use.
If it’s not a memory leak, then I think Lars should be awarded a Fields medal for his new data compression algorithm that achieves 2000% efficiency.

— End quote

The two have nothing to do with each other. I can start out with a blank piece of paper and fill it up with digits of the decimal expansion of pi… have I achieved infinite compression? It’s kind of like how having a vague notion of what a Fields medal is doesn’t mean you yourself actually know any math.

— Begin quote from ____

Also, I have no idea wtf Adobe’s doing behind the scenes when a flash game brings a computer that can run 3D games to its knees. I guess they don’t use hardware acceleration or something?

— End quote

Probably not. It’s not as if the whole point of using “Adobe” is rapid development and cross-platform compatibility.

I somehow don’t think it is appropriate for us to start a flamewar in this forum.
In any event, I thought I might politely point out that I was at the top of my Calculus class in college.
I’m 32 years old, and after running a successful business in the field, I was invited to work in Virtual Reality research.
My alma mater is the University of Lisbon, one of the oldest and most reputable in Europe, founded around 1200 AD.
I have presented my work at several conferences, overseen EU projects worth 900,000 euros, and published articles in scientific journals.
One of my papers was precisely about timer efficiency in message queued microthreading systems, where I proposed and benchmarked new algorithms to make our VR platform more efficient.
Nowadays I’m working on autonomous agent-based self-driving vehicles with artificial vision.
Granted, I certainly don’t know everything, but I’ll send you an autographed copy of my PhD thesis once I’ve finished it.

Wow, next time I need somebody to verb a noun, I know who to call.

— Begin quote from "Unchained"

There’s a world of difference between memory use and memory leak. None of those numbers sound outrageous for something written at such a high level, and you’d probably see them fall off if things got tight or something happened to trigger garbage collection.

edit: To be snide, the extra memory is probably being used to store the 6 miles of whitespace after every “W” in the character name/stat display font… wtf is up with that? :twisted: “Wendel” ends up looking like “W endel”

— End quote

No problem, I know what’s memory usage and memory leak. But that’s ok, I should have seen that there is garbage collection for this application, so it seems to be harder to realise where the problem is (but easier to fix). I don’t think the garbage collector is having problems, instead references may be kept alive accidentaly somewhere.

So… hi everyone…

At any rate, the general performance problems in flash/AIR are pretty well documented, and I’m by no means God’s gift to programming (I’m mostly self-taught, and was as an artist before I started coding about 15 years ago).

If it’s running slow or taking up too much memory/cpu on certain computers, there’s a few things I can do, most of which boils down to making sure that destructor functions are working properly and vigorously cleaning up references so that the garbage collector will kick in. This is especially important in complicated book-keeping data structures that can keep objects sticking around for the life of the program, which has been the source of most problems so far.

Another thing that might contribute to a high memory plateau even when it’s not growing is the fact that all the game’s assets are embedded in the executable itself - this is an artifact from early development when we planned on releasing this as a regular online flash game.

If I split off the game’s data files into a separate directory as loose data that’s only loaded in when needed, it should theoretically help. Of course, this requires digging out and replacing the whole asset loading pipeline, so it’ll likely be a while before we do that (it might have to wait for a sequel if it gets ugly enough).

At any rate, with every update or so I try to dig in there and clean out some more performance problems. Hopefully this will slowly get better over time, but short of porting the game to something like HaXe that gets me out from under Flash/AIR’s performance overhead, expect incremental fixes instead of miracles.

— Begin quote from ____

Another thing that might contribute to a high memory plateau even when it’s not growing is the fact that all the game’s assets are embedded in the executable itself - this is an artifact from early development when we planned on releasing this as a regular online flash game.

If I split off the game’s data files into a separate directory as loose data that’s only loaded in when needed, it should theoretically help. Of course, this requires digging out and replacing the whole asset loading pipeline, so it’ll likely be a while before we do that (it might have to wait for a sequel if it gets ugly enough).

— End quote

Your major gain here (and quite a gain it would be) would be allowing easy mods. Performance/resource-wise, I’d expect you to take a slight hit if anything. It might make somebody looking at a per-process resource manager happy, but once referenced that data’s going to be hanging around in various caches, SATA buffers, and the like.

People love seeing free RAM, but if I paid X for 4 gigs of ram and 2 gigs of it is constantly sitting empty, it seems obvious to me that I wasted X/2 of my hard-earned money. Watching a resource monitor is a great way to catch things that have gone off the rails, but whatever profiling your development tools have is probably tons better. Whatever allocation the OS actually does in practice is going to have little connection to your code because you’re writing at such a high level and a bunch of other factors are all trying to out-do each other in their efforts to predict this and pre-allocate that.

The move to loose files just adds yet another layer here as yet more layers try to read-ahead, predict, cache, pre-cache, pre-fetch. I can pretty much promise you that the one case it will not help is the person playing on an outdated e-machine that’s still using an IDE drive and is actually pushing the limits of their system RAM.

Cool - well that’s a good heads up then. I’ll stick to looking for object pointers that aren’t being nulled out in the debug profiler then, and move to loose files if/when we get around to handling mod support.

Oooh mods. I want me some space marines with alien revenants. :wink: