What are some good ways to squeeze in more fps in your app

Hi, I think the fps counters will be the death of me. As im worried my fps aren’t good enough (58, 60)

So, to help out the community and me, what are some good tips/tricks to get higher fps.

Thanks, Prynok

lol, I only start worrying when it gets below 25. Since 60 is the max, and we can only detect 30 or so, anything higher should be fine.

Optimising your speed depends a lot on what’s in your project.

Drawing is uually the main fps budget.
You can improve it to very nice perf by
1/ drawing things once to an image 2/ sprite the image where you need.
This is relly better than drawing each time. And use noSmooth().
Also: put collectgarbage() whereever you dereference big objects. This will smooth the resulting pace. Otherwise you may get an ugly1s stop from time to time.

Localise tables/variables and anything else you can think of, if any heavy loops are used then try and localise the containing code as it makes it quicker to process as its stored locally in a function instead of globally

The key is: identify which bit of code is the bottleneck. Othwerwise you’ll just end up optimising things that aren’t actually slowing you down.

This can be tricky to do in Codea, but an approach of disabling bits one by one and seeing when the speed comes up can work.

As well as judicious use of ‘local’ variables, I tend to avoid some of the built in table iterator functions (table.insert, table.remove, ipairs etc…) and use simple ‘for’ loops to iterate through to the end of the table (with #).

This can be a lot faster, especially if you need increased performance in your main game loop, albeit at the expense of readability of your code.

There was a really good thread on StackOverflow a while back that runs through a number of Lua performance optimisation tips:

http://stackoverflow.com/questions/154672/what-can-i-do-to-increase-the-performance-of-a-lua-program

Also, some good general Lua performance tips (explained in a fairly non techy under the hood way) here:

http://www.lua.org/gems/sample.pdf

Hope this helps…

:smiley:

Keeping a index on the table in a seperate variable which gets added to every time the table is added to is a quicker way of finding the sum of the table, # does this calculation in one frame which is slower, but about 0.1fps slower :wink:

I seriously emphasize using noSmooth() if drawing large shapes. For instance, I’m drawing fullscreen rectangles, and using noSmooth makes me go from 50 FPS to about 15 FPS. Also, suggest using meshes for some things, but only if you’re using many of the same object.