Lag

I have a relatively simple question with a complicated answer. Well, I’d think so anyway.

So that question: What causes lag in an app and how can we minimize it.

Basically my application gets lag spike whenever objects are created and “fly” past the screen. (just one example, not the real source of my problem) Now, right now I am not getting rid of the objects when they go off the screen, only when the person quits that section of the application. Can not getting rid of display objects when they are off the screen cause lag or does this just continue building memory? 

Can sfx playing cause lag? I’m not talking about playing a 3 minute song, I mean like a 3 second clip. 

Can downscaling/upscaling images cause lag as well? If image resolution is too big and you apply simple linear transformations to this image, does this cause lag?

Now, some of my inquiries are fairly straight forward with a “well, of course it does” kind of answer. But I am looking for more of a troubleshooting kind of response, with a technical explanation supporting the response. 

I’d accept links to blogs or guides on how to optimize stuff without sacrificing quality, but links to blogs or links about using display groups or scenes or sprite sheets etc have already been read

Now of course, If I am missing something that can cause lag then please mention it. 

I am fairly new to corona development and I am basically just trying to understand the sources of object stuttering in order to become a better developer. 

As my projects are slowly getting bigger I am making sure I don’t get fast results at the expense of poor performance. I’d like to do things “right”

Hi @rgame,

I’ll contribute a few points here, and let the community take it up from there:

  1. loading sounds on the fly can definitely cause lag. You should pre-load all sound files (even 3-second clips) in a non-time-sensitive point of your game.

  2. loading images on the fly can sometimes cause lag, especially if the images are large. You should try to pre-load large images in a non-time-sensitive place.

  3. creating physics bodies should be done beforehand as well, in most cases. Adding a few bodies on the fly won’t affect performance, but a large “batch” at once (10-20) may be noticeable.

  4. scaling/resizing objects on screen should not affect performance to any noticeable degree.

  5. you should optimize, optimize, and optimize again. If you haven’t read the guide on this, here it is: http://docs.coronalabs.com/guide/basics/optimization/index.html

Hope this helps,

Brent Sorrentino

  1. Makes sense.

  2. What API call preloads resource files such as images?

  3. Similar to 2, how to you preload an object before you create it to have a physics body? And what do you describe “on the fly” 

  4. I am surprised by that answer

  5. Clearly :slight_smile:

Hi @rgame,

I’ll contribute a few points here, and let the community take it up from there:

  1. loading sounds on the fly can definitely cause lag. You should pre-load all sound files (even 3-second clips) in a non-time-sensitive point of your game.

  2. loading images on the fly can sometimes cause lag, especially if the images are large. You should try to pre-load large images in a non-time-sensitive place.

  3. creating physics bodies should be done beforehand as well, in most cases. Adding a few bodies on the fly won’t affect performance, but a large “batch” at once (10-20) may be noticeable.

  4. scaling/resizing objects on screen should not affect performance to any noticeable degree.

  5. you should optimize, optimize, and optimize again. If you haven’t read the guide on this, here it is: http://docs.coronalabs.com/guide/basics/optimization/index.html

Hope this helps,

Brent Sorrentino

  1. Makes sense.

  2. What API call preloads resource files such as images?

  3. Similar to 2, how to you preload an object before you create it to have a physics body? And what do you describe “on the fly” 

  4. I am surprised by that answer

  5. Clearly :slight_smile: