How to find the reason for occasional stuttering

I’m writing a small/ simple game that in 99% of the times runs butter smooth @ 60 fps. But every now and then it stutters and I would really like to know why, because it really brings down the overall impression of the game.

For my normal debugging I use this line to watch the console printouts that I write myself:

adb logcat Corona:v *:s

I think I read a tip about showing everything with the line:

adb logcat

But that pours out a ridiculous amount of lines. I don’t even know where to begin and it’s really hard to tell where in the output the stuttering occured.

Is there a way to reduce the output to something a bit more manageable?

As LUA is not multi-threaded most likely what happens is that two processes happens at the same time and one of the process is so heavy that it causes the graphics to stutter.

I had (have) the same problem but I found that Corona Profiler helped me a lot: http://www.mydevelopersgames.com/profiler.html

It costs like 10 or 20$ and it’s totally worth the money.

Other than that make sure that you optimize your code - make sure you don’t recreate unnecessary objects (try to just move them out of screen etc.).

Best regards,

Tomas

Most of the time it’s the garbage collector kicking in, and even if you optimize the heck out of your game, a bit of stuttering from time to time is bound to happen (although wether you notice it or not is a different matter. Many users barely notice it).

As said by tomaswesterlund, keep destroy/create objects to a minimum, as that would make the garbage collector kick in way more often. Also, avoid using too many strings. For example, if you have a score counter that uses a text object, apart from the fact that each change to the .text parameter is quite taxing, everything you pass to it, even numbers, get converted to strings. 
LUA treats strings as normal objects, and keeps them to reuse them. So for example making a counter that goes from 1 to 100 in a small time with strings creates 100 different objects which will require the garbage collector to kick in.

Just linking this as I think it can be useful (so if any forum moderator think it is inappropriate, please feel free to remove it): http://ragdogstudios.com/2014/09/14/corona-sdk-improve-your-game-performances-with-object-pooling/

It’s a tutorial where we explain a bit how object pooling works and there’s also a small lib that helps dealing with it.

Thank you both.

tomaswesterlund:

I’ve also counted the milliseconds from the start to the end of the frameRedrawListener function (where “everything” happens) and I barely use 2-3% of the available time (on my SG5S that is…). I bought Corona Profiler, but I’, not sure it can help me if so little of the available frame time seems to be used.

But of course, it could be other things going on (for example garbage collection) that I cannot directly measure.

RagdogStudios:

I have tried to limit the created/freed objects to a minimum in-game (load/create objects once at init and then hiding them instead of deleting them etc). I also tried to remove the score text to see if it helped. It didn’t seem to make much difference.

But I’ll read more closely the web page that you linked to.

Thanks agani to both of you.

It’s a pain having no control over the garbage collection… the last time I wrote a game was in assembly for the Amiga… not much in the way of garbage collection then :slight_smile:

Are there any tools for hunting for (or somehow controlling) garbage collection at all when developing with corona?

You have some control over it. Look for garbage “set step” via google and you can see how it works. Basically it allows you to make the garbage collector kick in more often or less often

As LUA is not multi-threaded most likely what happens is that two processes happens at the same time and one of the process is so heavy that it causes the graphics to stutter.

I had (have) the same problem but I found that Corona Profiler helped me a lot: http://www.mydevelopersgames.com/profiler.html

It costs like 10 or 20$ and it’s totally worth the money.

Other than that make sure that you optimize your code - make sure you don’t recreate unnecessary objects (try to just move them out of screen etc.).

Best regards,

Tomas

Most of the time it’s the garbage collector kicking in, and even if you optimize the heck out of your game, a bit of stuttering from time to time is bound to happen (although wether you notice it or not is a different matter. Many users barely notice it).

As said by tomaswesterlund, keep destroy/create objects to a minimum, as that would make the garbage collector kick in way more often. Also, avoid using too many strings. For example, if you have a score counter that uses a text object, apart from the fact that each change to the .text parameter is quite taxing, everything you pass to it, even numbers, get converted to strings. 
LUA treats strings as normal objects, and keeps them to reuse them. So for example making a counter that goes from 1 to 100 in a small time with strings creates 100 different objects which will require the garbage collector to kick in.

Just linking this as I think it can be useful (so if any forum moderator think it is inappropriate, please feel free to remove it): http://ragdogstudios.com/2014/09/14/corona-sdk-improve-your-game-performances-with-object-pooling/

It’s a tutorial where we explain a bit how object pooling works and there’s also a small lib that helps dealing with it.

Thank you both.

tomaswesterlund:

I’ve also counted the milliseconds from the start to the end of the frameRedrawListener function (where “everything” happens) and I barely use 2-3% of the available time (on my SG5S that is…). I bought Corona Profiler, but I’, not sure it can help me if so little of the available frame time seems to be used.

But of course, it could be other things going on (for example garbage collection) that I cannot directly measure.

RagdogStudios:

I have tried to limit the created/freed objects to a minimum in-game (load/create objects once at init and then hiding them instead of deleting them etc). I also tried to remove the score text to see if it helped. It didn’t seem to make much difference.

But I’ll read more closely the web page that you linked to.

Thanks agani to both of you.

It’s a pain having no control over the garbage collection… the last time I wrote a game was in assembly for the Amiga… not much in the way of garbage collection then :slight_smile:

Are there any tools for hunting for (or somehow controlling) garbage collection at all when developing with corona?

You have some control over it. Look for garbage “set step” via google and you can see how it works. Basically it allows you to make the garbage collector kick in more often or less often