Tremendous performance loss when building for Android

I’m developing a game (fairly simple with a couple of screens and a few sprites) mainly for iOS but yesterday I decided to test it on an actual Android device (Nexus One) and there’s a significant loss in performance compared to testing on an iPod touch.

I’m talking about 500-900 millisecond response time when the screen is tapped on Android compared to instant response on iOS. In addition, when I use logcat to see what’s going on, it outputs things about “Grow Memory Heap”.

Any idea why this is happening?

Thanks! [import]uid: 8446 topic_id: 3319 reply_id: 303319[/import]

Can you give me a few more details.

What version of Corona are you using?
What is going on in your code when the touch happens? [import]uid: 3 topic_id: 3319 reply_id: 10165[/import]

Hi seanh, the structure of my project goes like this:

  • Main menu
  • Play
  • Game Screen
  • Screen has one background image
  • There’s an init() method that creates the initial 4 enemy sprites and adds them to a table (enemyArray)
  • The sprites have 4 frames each and they animate at about 600ms, and they contain an event listener on 'tap
  • There’s the game loop that moves the sprites and checks if they’re “dead” and should be removed

[lua]-- Function when the sprite is ‘tapped’
local killEnemy = function( event )
if event.phase == ‘began’ then
local target = event.target
target.taps = target.taps + 1
if(target.taps >= target.tapsToKill) then
target.isDead = true
end
end
end

– Main game loop
local gameLoop = function( event )
for i,obj in pairs(enemyArray) do
if obj.isDead == true then
table.remove(enemyArray, i)
obj:removeSelf()
else
obj.x = obj.x + 0.10
end
if obj.x > display.contentWidth then
obj.isDead = true
end
end

end[/lua]

I’m using the latest Corona Game edition by the way.

Thanks. [import]uid: 8446 topic_id: 3319 reply_id: 10183[/import]

There’s another case where the # of screen updates increase when the screen is touched, but it sounds like this is different. I’ll link this to that one so we look at them at the same time. [import]uid: 54 topic_id: 3319 reply_id: 10196[/import]

is it ok to call table.remove whilst looping through that table?

[import]uid: 6645 topic_id: 3319 reply_id: 10371[/import]

I’m not sure, but I don’t see why not.

Is there a reason you don’t simply remove the item in the function killEnemy()? [import]uid: 54 topic_id: 3319 reply_id: 11274[/import]

Thanks all, I’ve re-arranged the code around a bit and it now works as it should on Android. [import]uid: 8446 topic_id: 3319 reply_id: 11400[/import]

tjackiw, Would you mind sharing what you did to rearrange your code, so that others could learn what to avoid for android builds? I’ve tried building several of the sample projects for android and all the physics samples were dreadfully slow on my TMobile MyTouch. [import]uid: 11021 topic_id: 3319 reply_id: 11854[/import]

Greg, nothing really specific to report, I just re-factored the way I was doing the main game loop and that seemed to fix the lag during gameplay on a Nexus one. [import]uid: 8446 topic_id: 3319 reply_id: 11932[/import]