The most common causes of poor performance are:
Frequent garbage collection – In the older days you had to manually free up the memory, occupied from your objects or in other words destroy them. The things are different now – there is no such thing as manually destroying objects anymore, now GC is responsible for destroying unreferenced objects in programming languages like JAVA and C#.
But with great power comes great responsibility – you need to understand how GC works in order to harness its power and not diminish your performance.
– GC is only called when objects need to be freed from memory. GC can only destroy UNREFERENCED objects.
– On computer you may not recognize it, but on mobile GC will often pause for a few ms, leading to sudden lags and drops in FPS.
– You cannot tell GC how often to run, you can only manage how often you create and destroy objects
So you have to avoid basically two things: creating new objects and disposing of old objects in the game loop.
Good time for creating objects is for example when loading new level – not in the middle of it. But do not worry too much – the occasional creation of a String and etc. is certainly not a problem.
Another great technique is the Object Pooling – great article here http://gameprogrammingpatterns.com/object-pool.html. Basically you do not destroy objects, you just “reset” them for the next use.
Graphics and drawing – in this category we want to mention a couple of really good practices
– Use TexturePacker to pack your images in big power of two textures. The reason is simple – texture swaps are expensive operations, so drawing many things from the same texture is far better, than constantly swapping textures.
– Do not use unnecessary big images, that you need to scale down.
– Use culling – do not draw anything out of your screen. This one is a must, because drawing outside of the visible screen is completely pointless.
– Semi-transparency can be slow on some devices – When drawing images make sure you don’t have some semitransparent pixels in the background that you left by mistake. Also don’t draw too many sprites with alpha set to something other than 1. And don’t draw sprites that have alpha 0.
– Cut of calculations as much as possible for things, that are out of screen – do not animate stuff out of screen or at the very least animate less frequently.
And remember, that your main game loop is called around 60 times a second, so keep that in mind, when you decide to load some stuff or do some complex calculations every frame.