Performace assistance appreciated.

Hi all.
I’ve recently just about finished my first Solar 2D project, which has taken me years to accomplish in my spare time.
Well, I thought I had.
I generally test in simulator, with my CPU usage rarely going above a few percent.
I build every few weeks and have given apk’s to friends, no negative feedback there. However my partner has been doing a lot of testing over the last couple weeks as I was looking to release the game on Google Play, and I noticed when she played there was some fairly significant slowdown.
So I spent the last week or so going over the whole thing, changing sprites to images where I could get away with it, localising loads of functions, etc, changing multiple enterFrame listeners to timers.
However the crux of all of this is it’s pretty much made no difference.

In actual fact if I was totally honest it feels worse now than when I started. So I’m kinda gutted really. I’ve literally spent thousands of hours to get to “finished” state and in my opinion it’s speed is currently unacceptable/unplayable.

This is testing on a Lenovo Tab 3 Plus which is 8 core 2Ghz with 3Gb RAM.

I read a lot of optimisation stuff when I started. I’ve coded with it in mind the whole way through. I’ve read and re-read it all again over the last week. I’ve added a framerate counter which seems to steadily decrease whilst playing, but I don’t think I have any significant memory issues. Also, I don’t really feel like there’s enough going on to warrant the poor speed, but then I can’t really call myself a hugely experienced Solar2D developer…although before this I was starting to feel like it…!

Any ideas please from seasoned Solar2D vets? Would appreciate it a lot.
As I wanted to sell the game I’m actually not past paying money for someone to review the project and fix this.

Thanks for reading.
All the best,


There’s quite a lot that can be done to improve the performance of your game, but without seeing any code it isn’t that easy to help.

Using locals over globals is a good start. If you make many calls to some global functions, like math.random, for instance, then it is a good practice to localise these functions. Localising functions from the global table can increase the speed of some of these functions by more than 30%.

Limiting your use (and complexity) of your enterFrame listeners is also important. The more you have and the more complex they are, then the easier they’ll clog up your game’s performance.

How about your images? Are you using image sheets and are they, or your individual images, optimised? For instance, do you follow the power of two sizes or are your images of all shapes and sizes?

If your frame rate keeps dropping constantly, then you may have memory leaks (you can use my module to look out for them

Are you using Composer, and if so, then are you removing scenes when you no longer need them?

Well, there’s a lot more, but I’m really just throwing suggestions in the air as I don’t know the specifics of your project. :smiley:

Do you have a code profiler that you can use to find performance bottlenecks? I’m using an old Corona Profiler, but I don’t think that the developers are in business anymore.

1 Like

If your game is slowing down over time that’s probably a memory leak. You should look at both your Lua memory and texture memory as @XeduR suggested.

If loading times are way higher than you expect, you should look at the images you’re loading. For example, if you’re loading huge, screen size .png files then it’s pretty normal to see those slowdowns. You can avoid this by converting static background images to .jpg files where you can.

This is pretty general advice so without seeing your game it’s hard to know for sure if it will help with your issues but you may want to look into those.

1 Like

The other thing to check on is that you are removing objects when they are no longer used. I find that the number of display objects have a huge impact on performance.

We built this tool to count the number of objects and enterFrames in real time…


Hi guys, thanks for the feedback - it is greatly appreciated.

I don’t use global variables.
I’ve localised all functions used in loops.
I’ve removed all enterFrame listeners (except my newly created FPS counter), but am going to put one back in as I don’t like how it feels with a timer. It’s not overly complex anyway.

My images are are not in power of 2. They are random dimensions which output the smallest files from TexturePacker. But I don’t think it’s this.

I don’t think I have memory leaks, but have now added the collectgarbage(“count”) to my in app console output so will monitor this.

The app loads into about 205mb of texture memory then drops below 200 as the first level starts and does not go above it again.

It’s stating 1mb of memory - seems very low - from collectgarbage(“count”), I only added this in 2 days ago and did not work yesterday so will test this over the coming days.

I’m not using Composer.

I’m using a Profiler that I purchase a couple years ago for around $10 but I find it’s usefulness rather limited (i.e. none…!)

I will use XeduRs provided resources to investigate further, whilst stripping out (commenting) sections of code to reduce the app down until I find out what’s going on.

I will post back here when I find out what the bottleneck is. I still feel it’s codey though, not graphics.

I’ve also started monitoring collisions, counting them per second, it sometimes peaks above 1000 but does not correspond at all to the overall slowdown.

Thanks once more, hopefully my findings will be useful to others when I learn more.

All the best guys your support has made me feel a lot better already.

Love and best wishes,


1 Like

If you are using the built in Box2D physics library, then that may be the cause for the game slowing down. The physics engine is iterating through all of your physics bodies every frame, so their number and types can make a big difference.

You can improve the performance physics-wise by:

  1. Favouring local collision handling.
  2. Using as few dynamic bodies as possible.
  3. Limiting the number of active physics objects AND limiting the number of physics objects in general. For instance, can you disable all physics bodies (or even entire display objects) that are off screen and/or the player can’t interact with?

Hi all,
I’m still working on this.
Here’s an update for you:

Loading times are fine, it’s just bogging down when there are about half a dozen enemies on screen and you are interacting with them. The enemy sprites are animated with 9 frames and move via a transition with Sin wave easing.

In the past couple weeks I have:

  • Added a console which displays FPS, images created per second, sprites created per second, collisions per second and transitions per second, along with memory and texture memory usage. Thanks again to XeduR and ponywolf for the code. I also added a simple text update for other things, for example when an enemy is spawned or takes an AI decision.
  • Removed all string comparisons.
  • Removed all enterFrame listeners.
  • Reduced the amount of display groups from 10 to 6.
  • Localised all functions used in loops. I had already localised them but have now done so to a higher level.
  • Re-factored all my sprites. They are now all Power of 2 size and 1:2 or 2:1 ratio. I have also resized them so I do not scale in code.

The game uses about 1500Kb of memory when in use, and seems pretty consistent whilst playing, so looks like I have no memory leaks. After changing my sprites I’ve gone from around 200Mb of texture memory to around 160Mb.

The game looks and feels noticeably quicker now, however I’m still not happy with it. When things start to get hectic i.e. there are multiple enemies on screen and you are attacking them, the framerate drops. I think because I’ve optimised so much it seems more noticeable now - and once the slowdown has gone the FPS shoots back to 30 quickly and does not drop until the screen gets busy again.
After adding the stats provided by the guys above, it seems to be something to do with either collisions or transitions. I use transitions extensively and a lot of easing too. I’m going to start looking at this area next and will post an update when I’ve done so. Thanks again for all the assistance so far.

Warm wishes,


1 Like

How about some screenshots? Maybe I can see what’s going on… Also, enterFrames aren’t bad… is just an enterFrame with extra logic.

Also, that texture memory looks pretty high… How big is your biggest texture?

If you are using my visualMonitor, how many display objects does it say you have?


Thanks very much ponywolf, but I think it’s over.
I’ve spent a long time on this, and really haven’t been overambitious with what I wanted to achieve.
I’ve seen a lot of devices run a lot more complex software for the past several years.
All I can say at this point is it runs like a bag of utter garbage, and I’m completely out of ideas as to what it can be.
To say I’m not happy with it is a huge understatement.
I’m either off to a different engine or, more likely, laying down my dev hat.
To get slapped in the face just prior to launch with performance this appalling is something I’m struggling with greatly.

Changing to another engine can be a big hurdle. I’d at least consider providing a screenshot if it helps others narrow down on your issue as it might save you a lot of time.

Also, are you by any chance using image effects or blend modes?

1 Like

… or you can share a gameplay video with us. I’m pretty sure there’s something we can do before giving up a project you worked on for some time now. You can upload it to YouTube as an unlisted video and remove it later.


Thanks guys. I really appreciate your support. It is actually making me want to try and get this resolved, so it just goes to show even a few words can be worth so much.

I’ve got screen shots, it’s just trying to find some which highlight the problem. I’m not beyond uploading a video either.

I’m not using many effects at all no - none on the enemy sprites or attacks anyway.

I’ve got 2 more things I can think of:
The first is to take my object pooling up a level - well to the maximum I guess, so nothing apart from the enemies are being created during play.
Another is to re-do all my object filtering. Currently some objects I set to sensors so they don’t interact with others, but I guess these are still being handled as collisions. I really didn’t want to do this as I think I’m going to have to make a spreadsheet (as per the docs) which I wanted to avoid, as it’s not going to be small…

So expect this to take me another week or two I suppose. Which is fine currently as we’re still on lockdown here, so now is the time to do it.

Will come back again once more when this is done.

All the very best to you gentlemen.

1 Like

Late post, but hoping OP is watching.

@DigiNick - Been following. Looking forward to seeing your next post.

If still stuck then, consider having someone look at your game and/or share videos. We want to help, but it is hard w/ limited details.

Best of luck to you.


Hi all.
Was about to post again saying I’ve made leaps and bounds in performance, how, and why, and some of my code to help others.
However am now, using the latest build, experiencing crashes on device, where the whole thing just stops, no error codes, no indication why, nothing. Which is a massive game breaker whichever way you look at it.
I was literally just on the verge of saying performance is much better than it was, is acceptable, let’s release. Now I cannot. Absolutely no way of fault finding this either.
So looks like I’m shelving the whole project until further notice.
Thanks for the help all who tried, but am exceedingly disheartened, once more!
Shit happens I suppose.
All the best.

Just to state, I’ve never seen this behaviour before in Corona SDK. Even if code was running slow, I got something to go on, and was able to investigate further. Now it’s just crashes with no error messages and absolutely nothing to follow up on. So nowhere to go from here as far as I can tell. Not good.

Sad to hear that. I don’t want to say much because you may be a bit tired of that project, it happens to all of us. It would be a good idea to let it rest. Just one thing though, if it’s not mandatory it’s always a better choice not to update the SDK.

Hope you turn back to this and complete your project. Good luck!

If any of the Solar 2D engineers are reading and can help I would appreciate it.
I updated the SDK because I wanted to use offline builds as was getting anomalous compile issues that I wanted to investigate - turned out the option to deauthorise has disappeared so I cannot do so anyway…
If anyone else has any further ideas I’d appreciate it. The only thing I can think of is to downgrade the SDK again…simply nothing else to go on at this point :frowning:

Am rebuilding with 2019.3551 and will let you know how it goes.

It’s still halting with no errors.
Pretty savage to be honest.

If you can’t see any errors in console then it probably has something to do with your code. Can you make sure it’s a freeze and not anything related to your code? To make sure, you can keep an eye on your Runtime functions, enterFrame stuff, active buttons etc.