Terrible Performance on Samsung Galaxy S, crashes on Tegra Devices

I’m experiencing just absolutely terrible performance on a Samsung Galaxy S when trying to run a test application that has some assets from my upcoming game. I’m on build 484, building on Windows, not a subscriber (yet, perf is holding me back). It looks great in the simulator.

Here is the source code:
[lua]for i = 0, 21 do
for q = 0, 25 do
display.newImage(“Tile.png”, i * 34, q * 24)
end
end

pieces = {}
numPieces = 16

for i = 1, numPieces do
table.insert(pieces, display.newImage(“Piece.png”, math.random(750), math.random(350)))
end

local function movePieces()
for i = 1, numPieces do
transition.to(pieces[i], { time = 1000, x = math.random(750), y = math.random(350)})
end
end

Runtime:addEventListener(“touch”, movePieces)[/lua]

And I’ve uploaded my entire project folder here: http://simplyv4.com/Tactitest.zip

On the galaxy I get about 3-4 FPS. On a HTC Evo 4G I get about 20FPS (better, but definitely not very smooth animation). On a Nexus One I get probably 20FPS again, and very noticable lag on every touch. On the EVO the lag is not too crazy, but its there.

On an Atrix 4G the app doesn’t run, on a Xoom tablet it doesn’t run (not sure if Honeycomb works yet or not).

Am I doing something wrong? What’s the deal here, it doesn’t look like the graphical demands of my app are that high, and that little demo doesn’t feel smooth enough to use on any of the devices I’ve tested. [import]uid: 50524 topic_id: 9133 reply_id: 309133[/import]

Not sure exactly why the performance is so low, but my game also runs pretty dismally on my Samsung Galaxy S. The thing is, a friend of mine runs my game on ancient iPod Touch 2G and even that runs it really smoothly…

I did an Android build on an old 319 SDK and compared performance with a build with the new 484 and 489 builds and haven’t seen any performance increase at all unfortunately :S [import]uid: 9428 topic_id: 9133 reply_id: 33291[/import]

I can’t try it on a device right now but it’s obviously not much. It shouldn’t bring a powerful device to its knees. Anyway, on the simulator, it works perfectly well.

But to squeeze every bit of performance you can get, you should write your code like this:

[lua]for i = 0, 21 do
– cache the value as it does not need to be calculated every time
– you could also use for i = 0, 714, 34 do
– which should be (very) slightly faster
local currI = i * 34
for q = 0, 25 do
display.newImage(“Tile.png”, currI, q * 24)
end
end

– always use local variables as they are faster to access and are automatically GCed
local pieces = {}
local numPieces = 16

– cache the function
– this is much faster as calling math.random results in a lookup for math in the global table
– and then an access to a table member. quite slow if called many times
local rand = math.random

for i = 1, numPieces do
– don’t use table functions. they are slower because of the stack and whatnot
pieces[i] = display.newImage(“Piece.png”, rand(750), rand(350))
end

local function movePieces(event)
if event.phase == “began” then – restrict to only one phase. if you touch the screen and move the cursor/finger, you’ll generate dozen of unnecessary calls to movePieces
for i = 1, numPieces do
– using transition.to so many times is not the best idea. write your own code to do this as this adds a lot of timers
transition.to(pieces[i], { time = 1000, x = rand(750), y = rand(350)})
end
end

– to stop propagation and avoid unnecessary check for other listeners
return true
end

Runtime:addEventListener(“touch”, movePieces)[/lua]

I hope this helps.
Seth [import]uid: 51516 topic_id: 9133 reply_id: 33293[/import]

the bottleneck is transition to.

use foo:translate(x,y)

c. [import]uid: 24 topic_id: 9133 reply_id: 33298[/import]

Seth thanks for your comments. I tried them all with no difference.

Everything made sense other than:
[lua]-- using transition.to so many times is not the best idea. write your own code to do this as this adds a lot of timers
transition.to(pieces[i], { time = 1000, x = rand(750), y = rand(350)})[/lua]

For simple motions I should be writing my own code? Why is transition.to so slow?

Compared to some of the full screen 3D games that are pushing some massive features that run great, I’m really hoping I don’t have to walk on eggshells to get 30FPS in Corona :slight_smile: [import]uid: 50524 topic_id: 9133 reply_id: 33299[/import]

Thank you Carlos, if that’s the issue then I’ll work with it.

I should be calling an animate function then onFrameEnter, and writing my own linear animation utilities, in that case? [import]uid: 50524 topic_id: 9133 reply_id: 33300[/import]

Basically, what you should do is something like this (note however that this is not optimized. It is just to give you an idea):
[lua]for i = 0, 21 do
local currI = i * 34
for q = 0, 25 do
display.newImage(“Tile.png”, currI, q * 24)
end
end

local pieces = {}
local numPieces = 16
local rand = math.random

for i = 1, numPieces do
local piece = display.newImage(“Piece.png”, rand(750), rand(350))
piece.destX = piece.x
piece.destY = piece.y
piece.distX = 0
piece.distY = 0
pieces[i] = piece
end

local transitionTime

local function movePieces(event)
if event.phase == “began” then
for i = 1, numPieces do
local piece = pieces[i]
piece.destX = rand(750)
piece.destY = rand(350)
piece.distX = piece.destX - piece.x
piece.distY = piece.destY - piece.y
end
transitionTime = 1000
end
return true
end

local previousTime = system.getTimer()

local function animate(event)
local elapsedTime = event.time - previousTime
previousTime = event.time

if transitionTime > 0 then
for i = 1, numPieces do
local piece = pieces[i]
local p = 1000 / elapsedTime
piece.x = piece.x + piece.distX / p
piece.y = piece.y + piece.distY / p
end
end

transitionTime = transitionTime - elapsedTime
end

Runtime:addEventListener(“touch”, movePieces)
Runtime:addEventListener( “enterFrame”, animate )[/lua] [import]uid: 51516 topic_id: 9133 reply_id: 33305[/import]

Seth, thank you for the reply, however the code you posted still runs like complete crap on my Galaxy S.

For that matter, I tried just animating one piece and it still runs like crap.

The performance between transition.to and your custom animation function are the exact same visually. Your version runs better, pretty much acceptable performance on an Evo 4G.

I think there’s a big bug here on Galaxy S devices, considering the performance on a faster GPU is much slower than a device with a slower GPU (PowerVR SGX540 in Galaxy S vs. Adreno 200 in Nexus 1). [import]uid: 50524 topic_id: 9133 reply_id: 33307[/import]

On an Atrix 4G the app doesn’t run, on a Xoom tablet it doesn’t run (not sure if Honeycomb works yet or not). <<<< This is fixed in the latest daily build.

For Galaxy S - p4mance - stumped… i don’t know what to tell you.

C. [import]uid: 24 topic_id: 9133 reply_id: 33308[/import]

I’m sorry I can’t help you more as I don’t own an android device myself.

For the record, the version I posted above is just a test example. It doesn’t handle long “elapsedTime” and other stuff. [import]uid: 51516 topic_id: 9133 reply_id: 33309[/import]

Hi.

Interesting posts. I noticed that in your config file you use 60 frames per second setting. Could that be the problem? What if You tried 30 fps? Maybe drawings all these pieces between the screen refresh is too much for that device. I doubt it but worth a try.

Please take this as a grain of salt since I just started with Corona.

Cheers.

Mo [import]uid: 49236 topic_id: 9133 reply_id: 33324[/import]

Just a short question to be on the sure side: Corona Android uses NDK, right, it does not output a java based build?
Cause if it does, the performance you see is pretty reasonable and explainable as the java 2d performance is pretty bad (its pure cpu, now hw acceleration) compared by iOS pretty optimized native code 3d hw accelerated rendering through which any game, engine etc goes.

also the additional low performance: Am I right to assume you are still on android 2.1? if so upgrade, otherwise you are impacted by the famous galaxy s speedbug which causes a total file performance breakdown due to samsungs custom changes in their “android 2.1”. Android 2.2+ fixes it. [import]uid: 34188 topic_id: 9133 reply_id: 33331[/import]

I will try the other fps setting, and all devices tested are 2.2+ [import]uid: 50524 topic_id: 9133 reply_id: 33335[/import]

Setting fps to 30 made no dif for me. I have straight 2.2 Froyo on my SGS. I’ve done some reading and apparently 2.2 on Samsung is pretty rubbish but 2.2.1 supposedly improves things. I’m hoping so I’ll report back when I’m able to test. [import]uid: 9428 topic_id: 9133 reply_id: 33348[/import]

Wow your problem really bugged me. I had to find out what your problem was. I have a Samsung Captivate (Galaxy S) running 2.2 and tried your code it does run terrible.

You need to optimize you code by removing lines 1-5 because those lines create 525 bitmaps. Which are far too many to blit to the screen for a small device.

Instead use one background image for the checker board and it will run as smooth as silk.

I almost forgot to mention make sure you use 60 fps it runs much smoother than 30 fps.

Hope this helps.

Glenn [import]uid: 38820 topic_id: 9133 reply_id: 33695[/import]

I’d just add a note that if you set it to 60fps, be careful if you are using any physics. The physics (box2d) appears to be frame rate locked, so if your game can’t generate 60 frames per second, your physics scene will slow down and the game will appear to start running in slow motion.

Although using 30fps gives a less smooth overall frame rate, if using physics it seems that it can still run close to the speed its meant to without slow downs.

Thats my experience with the Galaxy S in any case…

Unfortunately for my game, I don’t use the enterFrame event at all for game logic. Everything is handled by touch events and transitions, which apparently Android doesn’t cope with too well… [import]uid: 9428 topic_id: 9133 reply_id: 33745[/import]

I disagree. The game I’m creating is a breakout type of game and it uses Corona build 484, the box2d physics of corona, 60 fps and with screen size set to 800x480 and as of right now it runs smooth and looks great with the high res. When it’s complete hopefully it stills runs as sweet.

I think Corona is a great tool but if your code is crap and or your images are too many or too big no game SDK in the world or game engine can fix that.

The saying GIGO

I’m not saying your code is crap or anyone elses. I’m not the best programmer either. I’m just saying my experience is that the problem isn’t Corona, box2d or the galaxy s. From my experience I did need to tweak my code a little here and there to get it to run fast and smooth. I think most game programmers need to optimize their code or images to some extend to get the results that their looking for. That’s all. [import]uid: 38820 topic_id: 9133 reply_id: 33823[/import]

I am just pointing out that the Box2D engine is frame rate dependant - it will not skip frames to keep the physics simulation running.

As for my issues with the Galaxy, I have my game running at 60fps perfectly smoothly on iPod 2G, iPhone 3GS, iPhone4, iPad.

When I build for Android, even limiting the graphics to low res, the same code base struggles to maintain 30fps at best. Like I already pointed out, apparently my software design approach doesn’t gel with the Android platform. I don’t use the enterFrame listener at all - I use transitions coupled with event listeners - in my game I’m only displaying 16 small icons on the screen at any one time - all fed by a spritesheet - not exactly a taxing job for a GPU.

I am not convinced that my code is badly optimised or my artwork is too big - its not, there is something inherently poor about either the Android build and how I am using Corona, or my particular 2.2 version of Android on my Galaxy S.

There doesn’t appear to be a magic list of what programming design patterns to avoid for the Android platform … I’m kinda in the dark trying to find how where the bottlenecks are for Android… I am certainly not the best programmer in the world either, but I’ve been doing software dev for long enough that this seems suss to me. [import]uid: 9428 topic_id: 9133 reply_id: 33866[/import]

First of all go for 319 build and You should read this article:
http://www.base2solutions.com/walkabout/Corona%20Tips.html [import]uid: 12704 topic_id: 9133 reply_id: 33867[/import]

I have done that, its a fantastic read thanks! There are some tips in there that I am checking out at the moment. [import]uid: 9428 topic_id: 9133 reply_id: 33868[/import]