Android very bad performance, need help!

I have an app, http://itunes.apple.com/app/rocket-space/id531141378
It works fine on any iOS devices and shows 60FPS even on iPhone 3GS.

But on android, I have 10-15 FPS, even on top Android devices with Tegra 2.
Amazon Kindle Fire works better, but not so smoothly as iOS, it shows only 19-23 FPS on device.
I tried to use different versions of the SDK, stable 704 and 840 and lot’s of daily builds. But this doesn’t help, I’ve got a perfomanse boost in 2-3 FPS on different versions, but it also left a bunch of restrictions to the code. I optimized the code wherever i can, cached bunch of variables, optimize onFrame calculation, but this doesn’t help )=

The game is pretty simple, I don’t know why it slows down… [import]uid: 131398 topic_id: 28011 reply_id: 328011[/import]

I recently had the same problem and unfortunately it’s kind of a code specific thing. What do you going on in your main game loop, which i assume is an enterFrame event?

I amanged to get my android build to an acceptable level but I do think it still runs a little smoother on my iOS devices. [import]uid: 147305 topic_id: 28011 reply_id: 113400[/import]

I don’t make anything special or hard for CPU in my main game loop. Move objects around the screen, based on my accelerometer data, destroy them if it moves out off bounds and spawn new object every second.

This is simple code of my game loop, but it still freezes:

[lua]local function checkForCoinsDrops()
local currentDropTime = coinsLastDropTime + coinsDropTimeInterval

if currentDropTime < lastTime then
local values = { 1, 1, 1, 1, 2, 2, 2, 5, 5, 10 }
local args = values[math_random( #values )]
local group = game.powerups.coinsGroup
local coin = PowerUpsFactory.create( “coins”, args )
group:insert( coin )
coinsLastDropTime = lastTime
end
end

local function updateGameObjects( deltaX, deltaY, timePassed )
local deltaX, deltaY = deltaX or 0, deltaY or 0

– move objects
for i = gameObjects.numChildren, 1, -1 do
local group = gameObjects[i]
for j = group.numChildren, 1, -1 do
group[j]:update( deltaX, deltaY, timePassed )
end
end

– move effects
for i = effectsGroup.numChildren, 1, -1 do
effectsGroup[i]:translate( deltaX, deltaY )
end

– create new if needed
checkForCoinsDrops()
end

local function updateInGame( timePassed )
– update rocket
local deltaX, deltaY = rocket:update( timePassed, rocketRotationX )
– move background
background:move( deltaX, deltaY )
– move objects
updateGameObjects( deltaX, deltaY, timePassed )
end

local function onFrame( event )
local timePassed = event.time - lastTime
lastTime = lastTime + timePassed

if currentGameState == GAME_STATES.IN_MENU then
updateInMenu( timePassed )
elseif currentGameState == GAME_STATES.IN_GAME then
updateInGame( timePassed )
end
end[/lua]
and
[lua]function object:update( deltaX, deltaY, timePassed )
self:translate( deltaX, deltaY )

– delete if out of bottom bound
if object.y - objectHalfHeight > screenHeight then
object:removeSelf()
object = nil
return
end

– flip coords if too far
local objectPosition = object.x
if objectPosition < leftBound then
object.x = rightBound
– print( “flip flip ?” )
elseif objectPosition > rightBound then
object.x = leftBound
– print( “flip flip ?” )
end
end[/lua] [import]uid: 131398 topic_id: 28011 reply_id: 114170[/import]

@sakharov I think the frame events are the issue try to rework parts of the code and test your code with the profiler from MY Developers. [import]uid: 86417 topic_id: 28011 reply_id: 114175[/import]

Just a small shot:

if you are really trying to get a [lua]math.random()[/lua] you should start “debugging” the line 6 of your code posted above, that says:

[lua]local args = values[math_random( #values )][/lua]

for

[lua]local args = values[math.random( #values )] --<Hope that helps, and as I said, just a shot.
Cheers,
Rodrigo.
[import]uid: 89165 topic_id: 28011 reply_id: 114177[/import]

@martin.edmaier I used this profiler, but it works only in simulator, and it shows that most of time spent on the [lua]obj:translate(x,y)[/lua] function.

@@RSCdev math_random is my cached local pointer to math.random. Like
[lua]local math_random = math.random[/lua] [import]uid: 131398 topic_id: 28011 reply_id: 114185[/import]

So, my shot has failed.

Excuse. [import]uid: 89165 topic_id: 28011 reply_id: 114229[/import]

@ sakharov have you tried to test it on a different phone? Maybe i can help out HTC Sensation and then maybe a logcat log… [import]uid: 86417 topic_id: 28011 reply_id: 114238[/import]

@martin.edmaier I tested on HTC Desire (~12 FPS), Samsung Galaxy Tab 2 (~14 FPS), Asus Transformer (~16-17 FPS), HTC Sensation XE (~22-25 FPS) and Amazon Kindle Fire (~20-24 FPS).
[import]uid: 131398 topic_id: 28011 reply_id: 114261[/import]