The more I optimize the worse the performance

I am getting a little frustrated. The more I am optimizing my code and making everything local the more my game is slowing down. What’s the deal? Has anyone else been seeing this?

I had everything global and it was fairly smooth now that almost everything is local. It is very choppy. [import]uid: 8192 topic_id: 4324 reply_id: 304324[/import]

Hello!
When I optimized my game, I checked all the images and wrote
[lua]object:removeSelf()
object = nil[/lua], and then everything run smooth and fast.

Also, I noticed fatal errors when tried to perform smthing like
[lua]group:remove(i)[/lua], so now I escape using this code.

What about global, surely you have to watch variable visibility, and you can use
[lua]local Gl = 1[/lua]in the very beginning of the program to create visible for everyone variable Gl.

Hope it was somehow helpful, and good luck! [import]uid: 8681 topic_id: 4324 reply_id: 13470[/import]

Thanks for the advice.
I am using spritesheets for everything. So I am trying to remove the sprite sheets. I do use the following code to remove objects from groups.

for i=paralax1.numChildren,1,-1 do  
 local child = paralax1[i]  
 child.parent:remove( child )  
 child = nil  
 end  
-- and I use this at the end of my unload function to dispose of the spritesheet and collect garbage  
spriteSheet:dispose()  
 local function collect ()  
 collectgarbage( "collect")  
 end  
 timer.performWithDelay(1, collect)  

Although, It seems that not everything gets removed, really don’t know why. What tools can I use to help me with performance? and tracking down what is slowing things down.

I am also declaring the variables local at the beginning of each file to make sure they have scope. [import]uid: 8192 topic_id: 4324 reply_id: 13487[/import]

for i=paralax1.numChildren,1,-1 do
local child = paralax1[i]
child.parent:remove( child )
child = nil
end

Don’t you face a termination of the Corona? I’m asking this 'cos it is common in my case: everytime I remove group this way, memory errors occur and Corona terminates. Sometimes I even do:
[lua]group:removeSelf()
group = nil[/lua]
And that works) [import]uid: 8681 topic_id: 4324 reply_id: 13490[/import]

No. I don’t get a termination. Strange that you do. YOu could actually declare the local outside of the loop as well. That would make it a little better. [import]uid: 8192 topic_id: 4324 reply_id: 13492[/import]

@amigoni

I experienced performance issues when I first started using Corona and discovered it was due to me leaving lots of print statements in my code which I was using for debugging. Thought it is worth mentioning just in case you have left any in your code. It really slows things down. Probably not your issue though. Good luck! [import]uid: 7863 topic_id: 4324 reply_id: 13520[/import]

@mediakitchen. I remember reading your post about that. It’s not my issue, but I think I found part of the issue.

It seems for some reason that if build to device and install your app, sometimes it’s best to reboot the device otherwise the performance is terrible.

I tried even deleting the app, but no luck. I don’t know why this is but. Rebooting or resetting the app seems to solve the issue. If anyone wants to shine in on this. Also this does not happen every time for some reason. [import]uid: 8192 topic_id: 4324 reply_id: 13522[/import]

I find this so odd. I’ve never encounter any performance issues, even though my code is terrible. I haven’t found the need to really try an optimize since it runs well on every device (except the simulator oddly enough).

The only thing that has ever affected performance was when I was drawing NewImageRects over and over. Everytime, framerate keep dorpping. Oddly enough it wasn’t an issue when it was just NewImage, but when I change them to support retina graphics performance went to the drain (though for some reason, not memory usage), (even on non retina devices, loading the low res graphics). Simply removing the previous images, before drawing again solved all my issues.

I simply can’t imagine a print statement affecting performance in any way (I have lots on my enterFrame listeners). [import]uid: 10835 topic_id: 4324 reply_id: 13525[/import]

@Ignaciolturra. I have a very big rectangle in my graphics. I will remove it and see what happens. I thought it would be better to have it then to have an image but I guess not. [import]uid: 8192 topic_id: 4324 reply_id: 13526[/import]

@IgnacioIturra

I was surprised too as I am used to leaving loads of trace statements in my Flash games. However another member on the Forum highlighted the issue and removing the print statements had a huge impact on performance [import]uid: 7863 topic_id: 4324 reply_id: 13613[/import]