Optimizing Code

Okay, so I bet half of you have already pulled up this article

http://developer.coronalabs.com/content/performance-and-optimization

Assuming I have already done everything on that list, how can I simplify and optimize my project?

I noticed I called display.newImageRect and math.random/math.round probably 100 times a second. 
I made those local by doing
[lua]local newImg = display.newImageRect

local mRand = math.random

–ETC pre-declaring all SDK calls[/lua]

This added back MAYBE 1 fps

Is there much else I can do?

Localizing the creation of 100’s of images isn’t going to make the performance any better, it will just make every a bit easier to understand. 

Are you nilling out unused imageRects? Do you really need to create that many? Do they all have physical shapes? Do you have a large amount of enterFrame Runtime listeners running in your app? The answer to these questions might help to re-factor your app and make it a bit more stream-lined and increase performance.

Also, remember that certain devices are more powerful than others. If you are only getting 1 FPS on the simulator, you’ve got a serious problem and should look into memory leaks. Best place to start is to implement a performance meter if you haven’t already

http://developer.coronalabs.com/code/easy-use-performance-meter-memory-texture-memory-fps

Thanks for the reply!

I do have a little module that tells me about my FPS. What I meant by that 1 FPS was instead of occasionally hitting a low of 20 FPS I would occasionally get a low of 21 FPS. It could just be placebo effect though and I really haven’t even improved performance  :lol: 

This is a side-scroller style game so things get added off screen then removed or moved when they hit the other side of the screen. However, as I add new things, I’m worried it will really bog down. 

There are only two runtimes. One for my faux-physics and another for collision.

You did however make me realize that I could rework one thing that might add a small boost in performance.

If you care to see a video of the game, go through the link.
http://coltmakesgames.tumblr.com/post/58306930738/flying-sloths-this-is-my-indie-game-soon-to-be

Glad I could help!

I guess my only other suggestion would be to take a look at how you’re removing/nilling items once they are collected/removed from the game screen. I had a bear of a time with this as I found that I needed to re-work my entire deletion logic.

Localizing the creation of 100’s of images isn’t going to make the performance any better, it will just make every a bit easier to understand. 

Are you nilling out unused imageRects? Do you really need to create that many? Do they all have physical shapes? Do you have a large amount of enterFrame Runtime listeners running in your app? The answer to these questions might help to re-factor your app and make it a bit more stream-lined and increase performance.

Also, remember that certain devices are more powerful than others. If you are only getting 1 FPS on the simulator, you’ve got a serious problem and should look into memory leaks. Best place to start is to implement a performance meter if you haven’t already

http://developer.coronalabs.com/code/easy-use-performance-meter-memory-texture-memory-fps

Thanks for the reply!

I do have a little module that tells me about my FPS. What I meant by that 1 FPS was instead of occasionally hitting a low of 20 FPS I would occasionally get a low of 21 FPS. It could just be placebo effect though and I really haven’t even improved performance  :lol: 

This is a side-scroller style game so things get added off screen then removed or moved when they hit the other side of the screen. However, as I add new things, I’m worried it will really bog down. 

There are only two runtimes. One for my faux-physics and another for collision.

You did however make me realize that I could rework one thing that might add a small boost in performance.

If you care to see a video of the game, go through the link.
http://coltmakesgames.tumblr.com/post/58306930738/flying-sloths-this-is-my-indie-game-soon-to-be

Glad I could help!

I guess my only other suggestion would be to take a look at how you’re removing/nilling items once they are collected/removed from the game screen. I had a bear of a time with this as I found that I needed to re-work my entire deletion logic.