Performance problem

Hi, I’m close to finishing my first Corona game and have noticed that as the game goes on, it progressively slows down.

I’ve done quite a bit of reading on this topic and the most common problems seem to be memory leaks, transitions and runtime listeners. I believe I have eliminated all those causes by not using transitions and carefully managing my runtime listener(s). All objects, listeners etc get removed and nil-ed when no longer in use. I confirm that this is working and that there are no memory leaks with the module found here:

https://forums.coronalabs.com/topic/50059-memory-problems-and-cant-find-it/

Memory fluctuates ever so slightly (± 0.5% range) and I check this every second. I’ve discarded the scene manager (temporarily) to make sure I have full control over when objects and listeners get removed. The game relies heavily on physics and the slow down appears on both Android and iOS. It is very reproducable, i.e. happens every time.

I’m at the stage where I’ve run out of ideas, so would appreciate any suggestions as to where I might look next. Thanks!

Verify all listener are remove by add some print in each listener you have.

Use glider to know which function are very heavy. It give you many usefull information

Thanks, I made sure with print statements in each of my listeners, that they all get removed correctly.

Any other things I could be looking at other then listeners, transitions and removal of objects?

Have you turned on physics “hybrid” mode for debugging physics? Can you make sure you’re physics objects are also getting cleared?

Rob

Thanks Rob, I can confirm via hybrid mode that there are no left-over physics objects lingering around. The problem also appears in the simulator, so I don’t think it’s a matter of the devices not being powerful enough either.

I don’t know the kind of game you are making and I know it’s a long shot but is there a chance you may be creating backgrounds or objects more than one time?

Also, is it the texture memory or Lua memory that is getting loaded up?

Thank you for all the suggestions! I’m making a physics based puzzle game. When debugging, I stopped the game after every level, verifying that I’m left with a blank screen to ensure all objects including the background are removed.

That’s an interesting question, I don’t know whether it is texture memory or Lua memory. I had a look through the memory leak module I’m using and it obtains memory usage as follows:

currentMemoryUsage = collectgarbage(“count”)

I’m also a bit surprised, that the game will slow down on in the simulator on my development machine (which is a lot more powerful than any mobile device). Is there some sort of a threshold when a game gets throttled?

collectgarbage(“count”) returns the memory being used by Lua. This is for tables, strings, etc. It’s usually a value in the 100,000’s of bytes order and for some apps, it might climb to a megabyte or two. Generally speaking Lua memory is less than a single image loaded as a background (texture memory). Texture memory is the memory used by your graphics.  The API to get that is:

system.getInfo(“textureMemoryUsed”)  (https://docs.coronalabs.com/api/library/system/getInfo.html#texturememoryused)

This returns the amount of memory in bytes used by graphics and images. Divide it by (1024*1024) to convert it to Megabytes which is a more useful value to look at.  FWIW, collectgarbage(“count”) returns the memory in “Kbytes”. If you want to see that value on the same scale as your texture memory, divide by 1024, though honestly, kbytes is a good scale for that since you’re generally dealing with several hundred kbytes of Lua memory. Most people don’t want to deal with 7+ digits of for texture memory, which is why I recommend converting to MegaBytes first.

Anyway, if you’re not looking at texture memory, that would be a great place to start. Your device (and simulator) are rarely going to run low on memory due to Lua memory usage, texture memory usage is where you’re going to start pushing your device’s limits. You might find on some devices you might only have 50mb of memory available to you. Modern devices could get you a few hundred megabytes of memory to use.

Finally, check to make sure to check your audio. There isn’t a way to measure how much memory audio is taking up, but it can be a sizable drain too.

Rob

Thanks Rob,

Really appreciate the in-depth reply. I was not aware of the texture memory. I test for both now every second:

  • Lua memory: depends on game level, but average is at 660kb, with fluctuations up and down in the 0.5% range as the level gets played

  • Texture memory: between 5.0 and 6.5mb (again depending on game level), with no fluctuations whatsoever as level gets played (unless an object gets removed, then it goes down accordingly)

I will completely remove all audio next and see if that makes a difference.

Update after a few more days of testing: Removing all audio does not make a difference. Is there anything else I could be missing?

I’m sad to see that it all came down to this but can you comment out all parts of your code and include them one at a time so you can see which part causes the problem?

Hi hmhm,

what exactly is running slow? Have you set the framerate to 60?

I’m not sure that’ll solve the problem, because you aren’t using transitions etc but it’s worth the shot!

Once again thank you for all the replies and ideas!

@ bgmadclown: I’ve done that as far as I could take it (that’s usually my first debugging approach). The game relies heavily on physics and liquidfun; for instance if I un-comment the liquidfun particles, then the game simply won’t be playable and I can’t progress to the stage where it slows down.

@ bramvbilsen: that is correct, it runs at 60fps

Can you send out a build via TestFlight? If so, I can send you my e-mail address through messages. I would like to take a look at what happens in the game.

Thank you for the offer, I will send you an email.

Verify all listener are remove by add some print in each listener you have.

Use glider to know which function are very heavy. It give you many usefull information

Thanks, I made sure with print statements in each of my listeners, that they all get removed correctly.

Any other things I could be looking at other then listeners, transitions and removal of objects?

Have you turned on physics “hybrid” mode for debugging physics? Can you make sure you’re physics objects are also getting cleared?

Rob

Thanks Rob, I can confirm via hybrid mode that there are no left-over physics objects lingering around. The problem also appears in the simulator, so I don’t think it’s a matter of the devices not being powerful enough either.

I don’t know the kind of game you are making and I know it’s a long shot but is there a chance you may be creating backgrounds or objects more than one time?

Also, is it the texture memory or Lua memory that is getting loaded up?