Slow performance on Android device, not fps connected. Help needed!

I am trying to compile one of my games for Android devices. The game runs just fine on the simulator but when installed on an actual device (e.g. Samsung Galaxy S), things are acting really slow. And with “slow” I do not mean low fps during gameplay but slowness in the game menus.

Example: The main game menu is shown where the player can choose to start a new game, see intructions or the highscores. When the player taps on any of these buttons, the main game menu moves out of the visible area and the chosen sub-menu should slowy fade in. However, 2-3 seconds pass before the chosen menu is shown just as if the programm is “stuck” for a moment. There are no animations or CPU intensive calculations going, there are just a few transitions with button widgets (using own images) initiated.

Has anyone experienced the same? I just can not find out what is wrong, all runs fine on iOS devices but not on Android…Is this connected to using widgets?

Any help/input is greatly appreciated!

Thanks,

Jens

Hi Jens,

Have you maxed out (or nearly so) your texture memory? This can drag an app to its knees, if not crash it outright.

Brent

Hi Brent,

I narrowed it down by removing lines of code and it seems as if widget.newButton is the troublemaker. It definitely slows down the app on Android devices. The funny thing is that I am only creating three widget buttons in one of the game menus and calling the menu takes up to 2 seconds. No idea how to fix this. All runs fine & fast on iOS devices with the same code.

I am currently using build 2013.1101 but I came across this issue already more than half a year ago.

Any hints?

Jens

Hi Jens, Can I see some code related to this? Where you declare the buttons, the listener function you’re using, etc.

Hi Brent,

here is the code-block that seems to make trouble. Please let me know if you need more:

[lua]

  – draw box
  local instructionsbox = display.newImageRect(“images/COMMON/instructionsbox.png”, 300, 340)
  instructionsbox.x = screenCenterX
  instructionsbox.y =  screen.bottom - 150 + scaleData.spacer_20px - scaleData.kindleFireBoxAdder
  instructionsbox.alpha = 0

  local longline

    – display long line below logo
  if scaleData.isIPAD then
       longline = display.newImageRect(“images/COMMON/longline.png”,270, 2)
    elseif gameData.isKindleFireHD9 then
     longline = display.newImageRect(“images/COMMON/longline.png”,268, 2)
  else
     longline = display.newImageRect(“images/COMMON/longline.png”,290, 2)
  end

  longline.x = screenCenterX
    longline.y =  screen.top - 130 + scaleData.kindleFireButtonAdder
    longline.alpha = 0

  – draw “back” button
  local backButton = widget.newButton {
                                      defaultFile     = “images/COMMON/button_back.png”,
                                      overFile        = “images/COMMON/button_back_down.png”,

                                      left      = screen.left + 15 + scaleData.reducer_30px + scaleData.iPad1_18px - scaleData.kindleFireButtonReducer - scaleData.kindleFireTextReducer,
                                      top       = screen.bottom - 50 - scaleData.spacer_5px - scaleData.kindleFireBottomReducer,

                                      width       = 35,
                                      height      = 35,
                                          
                                      onPress     = function () if gameData.busy == false then playSound(sound.buttonClick) end end,
                                      onRelease   = function () if gameData.busy == false then gotoMainMenu() end end,
                                    }

  backButton.alpha = 0

  – Kindle Fire specific changes
  if gameData.isKindleFire then
    backButton.x = backButton.x + 10
  end

  – draw “next” button
  local nextButton = widget.newButton {
                                      defaultFile     = “images/COMMON/button_forward.png”,
                                      overFile        = “images/COMMON/button_forward_down.png”,

                                      left            = screen.right - 55 - scaleData.reducer_25px - scaleData.iPad1_10px + scaleData.kindleFireButtonAdder,
                                      top             = screen.bottom - 50 - scaleData.spacer_5px - scaleData.kindleFireBottomReducer,

                                      width           = 35,
                                      height          = 35,
                                          

                                      onPress         = function () if gameData.busy == false then playSound(sound.buttonClick) end end,
                                      onRelease       = function() if gameData.busy == false then showInstructions(“next”) end end,
                                    }

  nextButton.alpha = 0

  – draw “previous” button
  local previousButton = widget.newButton {
                                      defaultFile   = “images/COMMON/button_backward.png”,
                                      overFile      = “images/COMMON/button_backward_down.png”,

                                      left      = screen.right - 110 - scaleData.reducer_10px - scaleData.iPad1_5px,
                                      top       = screen.bottom - 50 - scaleData.spacer_5px - scaleData.kindleFireBottomReducer,

                                      width       = 35,
                                      height      = 35,
                                          
                                      onPress     = function () if gameData.busy == false then playSound(sound.buttonClick) end end,
                                      onRelease     = function() if gameData.busy == false then showInstructions(“previous”) end end,
                                    }

  previousButton.alpha = 0

  – make Kindle Fire specific changes
  if gameData.isKindleFire then
    nextButton.x = nextButton.x + 4

 
  elseif gameData.isKindleFireHD9 then
    previousButton.x = previousButton.x + 8
  end

[/lua]

Jens

Is this also slow for you on daily build 1080 ?

Hi Danny,

I tested build 1080 and it is doing much better! Compared to iOS there is still a bit of a delay when testing on my Galaxy Note / Galaxy S devices but much less than with daily build 1101. Seems as if something has changed inbetween the builds. Could you fix this and bring the speed for widets back up again or make them even faster?

Would be great if widgets on Android devices could perform just as well as on iOS devices (e.g. having the app not slow down when using widgets).

Jens

Thanks for the reply Jens.

This isn’t a widget bug, it is related to plugins. 

I recommend you read Josh’s response at the end of this thread: http://forums.coronalabs.com/topic/34701-android-acting-really-slowly-simulator-and-ios-ok/

Which is the same issue you are facing.

Thanks

Danny,

I am loading the widget plugin within my main.lua file during startup of the game. This only happens once and the plugin is not re-loaded afterwards. Still I am having the same issues like the other developer in the thread that you have linked to.

Is there any other workaround or do I need to load the widget plugin from within another file than my main.lua file? This is quite critical.

Thanks,

Jens

Hi Jens,

I haven’t been entirely “in the loop” on this specific thread, but what Danny is referring to is the Corona Plugin system that’s being implemented. As Joshua indicates in the other thread, this will be addressed as the Plugin system gets further along… so at this point, the only workaround is what has been suggested in the other thread… but certainly, we’re aware of the issue. :slight_smile:

Brent

Brent,

thank you. I wanted to try the workaround in the other thread but that workaround is based on the assumption that you require the widget plugin multiple times. I do it only once in my main.lua so the workaround will not work for me. Maybe I missunderstood the workaround in the other thread and someone could give me a hint.

Jens

Hi Jens,

Have you maxed out (or nearly so) your texture memory? This can drag an app to its knees, if not crash it outright.

Brent

Hi Brent,

I narrowed it down by removing lines of code and it seems as if widget.newButton is the troublemaker. It definitely slows down the app on Android devices. The funny thing is that I am only creating three widget buttons in one of the game menus and calling the menu takes up to 2 seconds. No idea how to fix this. All runs fine & fast on iOS devices with the same code.

I am currently using build 2013.1101 but I came across this issue already more than half a year ago.

Any hints?

Jens

Hi Jens, Can I see some code related to this? Where you declare the buttons, the listener function you’re using, etc.

Hi Brent,

here is the code-block that seems to make trouble. Please let me know if you need more:

[lua]

  – draw box
  local instructionsbox = display.newImageRect(“images/COMMON/instructionsbox.png”, 300, 340)
  instructionsbox.x = screenCenterX
  instructionsbox.y =  screen.bottom - 150 + scaleData.spacer_20px - scaleData.kindleFireBoxAdder
  instructionsbox.alpha = 0

  local longline

    – display long line below logo
  if scaleData.isIPAD then
       longline = display.newImageRect(“images/COMMON/longline.png”,270, 2)
    elseif gameData.isKindleFireHD9 then
     longline = display.newImageRect(“images/COMMON/longline.png”,268, 2)
  else
     longline = display.newImageRect(“images/COMMON/longline.png”,290, 2)
  end

  longline.x = screenCenterX
    longline.y =  screen.top - 130 + scaleData.kindleFireButtonAdder
    longline.alpha = 0

  – draw “back” button
  local backButton = widget.newButton {
                                      defaultFile     = “images/COMMON/button_back.png”,
                                      overFile        = “images/COMMON/button_back_down.png”,

                                      left      = screen.left + 15 + scaleData.reducer_30px + scaleData.iPad1_18px - scaleData.kindleFireButtonReducer - scaleData.kindleFireTextReducer,
                                      top       = screen.bottom - 50 - scaleData.spacer_5px - scaleData.kindleFireBottomReducer,

                                      width       = 35,
                                      height      = 35,
                                          
                                      onPress     = function () if gameData.busy == false then playSound(sound.buttonClick) end end,
                                      onRelease   = function () if gameData.busy == false then gotoMainMenu() end end,
                                    }

  backButton.alpha = 0

  – Kindle Fire specific changes
  if gameData.isKindleFire then
    backButton.x = backButton.x + 10
  end

  – draw “next” button
  local nextButton = widget.newButton {
                                      defaultFile     = “images/COMMON/button_forward.png”,
                                      overFile        = “images/COMMON/button_forward_down.png”,

                                      left            = screen.right - 55 - scaleData.reducer_25px - scaleData.iPad1_10px + scaleData.kindleFireButtonAdder,
                                      top             = screen.bottom - 50 - scaleData.spacer_5px - scaleData.kindleFireBottomReducer,

                                      width           = 35,
                                      height          = 35,
                                          

                                      onPress         = function () if gameData.busy == false then playSound(sound.buttonClick) end end,
                                      onRelease       = function() if gameData.busy == false then showInstructions(“next”) end end,
                                    }

  nextButton.alpha = 0

  – draw “previous” button
  local previousButton = widget.newButton {
                                      defaultFile   = “images/COMMON/button_backward.png”,
                                      overFile      = “images/COMMON/button_backward_down.png”,

                                      left      = screen.right - 110 - scaleData.reducer_10px - scaleData.iPad1_5px,
                                      top       = screen.bottom - 50 - scaleData.spacer_5px - scaleData.kindleFireBottomReducer,

                                      width       = 35,
                                      height      = 35,
                                          
                                      onPress     = function () if gameData.busy == false then playSound(sound.buttonClick) end end,
                                      onRelease     = function() if gameData.busy == false then showInstructions(“previous”) end end,
                                    }

  previousButton.alpha = 0

  – make Kindle Fire specific changes
  if gameData.isKindleFire then
    nextButton.x = nextButton.x + 4

 
  elseif gameData.isKindleFireHD9 then
    previousButton.x = previousButton.x + 8
  end

[/lua]

Jens

Is this also slow for you on daily build 1080 ?

Hi Danny,

I tested build 1080 and it is doing much better! Compared to iOS there is still a bit of a delay when testing on my Galaxy Note / Galaxy S devices but much less than with daily build 1101. Seems as if something has changed inbetween the builds. Could you fix this and bring the speed for widets back up again or make them even faster?

Would be great if widgets on Android devices could perform just as well as on iOS devices (e.g. having the app not slow down when using widgets).

Jens

Thanks for the reply Jens.

This isn’t a widget bug, it is related to plugins. 

I recommend you read Josh’s response at the end of this thread: http://forums.coronalabs.com/topic/34701-android-acting-really-slowly-simulator-and-ios-ok/

Which is the same issue you are facing.

Thanks

Danny,

I am loading the widget plugin within my main.lua file during startup of the game. This only happens once and the plugin is not re-loaded afterwards. Still I am having the same issues like the other developer in the thread that you have linked to.

Is there any other workaround or do I need to load the widget plugin from within another file than my main.lua file? This is quite critical.

Thanks,

Jens

Hi Jens,

I haven’t been entirely “in the loop” on this specific thread, but what Danny is referring to is the Corona Plugin system that’s being implemented. As Joshua indicates in the other thread, this will be addressed as the Plugin system gets further along… so at this point, the only workaround is what has been suggested in the other thread… but certainly, we’re aware of the issue. :slight_smile:

Brent