Performance...is this normal?

In part of my app I create a List View of 10 items. Each item consists of a Group with an icon image, rectangle background, and text line.

Creating and displaying this List View takes about 5 seconds on a DroidX, which is a fairly fast Android device. Takes about 3 seconds to display on the original iPod touch. Those are the only devices I have available to test on.

Obviously, a delay of 3-5 seconds when tapping a button before anything is displayed is too long. And this is just with 10 items in the list.

It takes the same time the second (and subsequent) times I load the List View, so even though Corona is supposed to cache the images, I don’t see that having much effect.

What is taking so long to display this? Are these kind of performance numbers normal? Why is a newer Android device so much slower compared to an old iPod touch device?

What are other people experiencing with app performance on real devices? [import]uid: 12529 topic_id: 7112 reply_id: 307112[/import]

Hi, is it possible to show some code? Sound slike you have somewhere a delay. [import]uid: 5712 topic_id: 7112 reply_id: 24991[/import]

Here is the function that creates the new display group:
[lua]function new()
local group = display.newGroup()
local back = display.newImage(“background.png”)
group:insert(back)

local eqList = tableView.newList{
data = itemList,
callback = function(row)
local itemRect = renderItem(row)
return itemRect
end
}
group:insert(eqList)
return group
end[/lua]
The itemList is a table of objects. Here is the renderItem routine:
[lua]function renderItem( self)
local frameHeight = 48;
local pictureRadius = 24;
local nameMargin = {10,8};
local margin = 24
local textSize = 18
local iSlot = self.iSlot
local iType = self.iType
local width = display.contentWidth-2*margin

local group = display.newGroup()

local frame = display.newRoundedRect( 0, 0, width, frameHeight, 10);
frame:setFillColor( rgb( itemColor[iType] ))
frame:setStrokeColor( 80, 80, 80);
frame.strokeWidth = 2;
group:insert( frame);

local offsetX, offsetY = 5, 1

local circ = display.newCircle( pictureRadius+offsetX, pictureRadius+offsetY, pictureRadius+2)
circ:setFillColor(0,0,0,120)
group:insert(circ)

local disc = display.newImageRect( “disc.png”, pictureRadius*2, pictureRadius*2)
disc.x = pictureRadius+offsetX
disc.y = pictureRadius+offsetY
group:insert( disc);

local image = display.newImageRect( itemImage[iSlot], disc.width*0.7, disc.height*0.7)
image.x = disc.x
image.y = disc.y
group:insert(image)

local itemName = display.newText( self.name, pictureRadius*2 + nameMargin[1], nameMargin[2], nil, textSize)
itemName:setTextColor( rgb( itemTextColor[iType] ))
group:insert(itemName)

return group
end[/lua]
As you can see, the “self” item has several properties for name, color, type, etc. And for each type/slot there are arrays for color and the image name. So I can’t really give *all* the code without making this a huge post that nobody will read. But you can see that I’m just calling normal Corona routines for rectangles, images, text, etc. [import]uid: 12529 topic_id: 7112 reply_id: 25002[/import]

There should be a over loop or something as Mike suggested.

Depends on you calling renderItem. A sudden overloading graphical initialisations due to for loops, or recursive looping will lag the system for a few seconds especially if there are a lot of icons/items, and if your list is really big.

Instead of using for loops, try using a timer to do the loop, so the stress on say adding 100 list items won’t be that high, hence, you don’t feel the lag/delay. [import]uid: 6066 topic_id: 7112 reply_id: 25007[/import]

Are you calling renderItem each frame?

Maybe it is the item loading. Preload them and store them in dummies. That makes sure that each icon is staying inside the memory and then the cache approach will help.

But there must be sometthing strange going on in your code logic. I am helping someone atm with his app to fix some leaks and stuff like that. He has huge list in there and so far this are fast like expected. But he has only text and no images in the list. [import]uid: 5712 topic_id: 7112 reply_id: 25050[/import]

Guys, I’m using the List View component. Make sure you have used that before commenting.

When you create a List View (via tableView.newList) you pass the “data” property as a table to be looped through and a “callback” routine that is responsible for creating each display item in the list.

In my case, “data” is a table of 10 “item objects”, and the “callback” routine calls renderItem to create each list element.

So renderItem is not being called for each frame. It is just called once for each item in the list when the list is initially created.

Once the list is created, it scrolls just fine and is perfectly responsive.

It’s just the initial creation time that is slow, and again, this is only for TEN items in the list.

Corona should be caching the images internally itself, so I shouldn’t need to create additional references to them. In fact, doing so did not change the list creation time at all.

All I can think of is that newImageRect maybe is slow because of the additional image scaling that it does. I will play around with the renderItem code and remove various parts of it to see if I can determine which part is slow.

Also remember that this is mostly an Android issue. If you have any iOS device newer than the 1st gen iPod Touch, then you probably won’t notice the delay. But on a DroidX, the delay is significant. And a DroidX is considered a fast Android device.

You will never see any delay if you are just using the Simulator. [import]uid: 12529 topic_id: 7112 reply_id: 25137[/import]

It’s definitely the images. A combination of two things:

  1. Using newImageRect instead of newImage is definitely slower (as expected).

  2. Even using newImage makes it slow. If I remove both images, then the screen loads in about 1 second instead of 5.

Not sure why loading images, even when they are cached, is taking so long. Maybe Corona is not caching on Android somehow?

I’m going to try and implement my own caching and see what happens. [import]uid: 12529 topic_id: 7112 reply_id: 25156[/import]

Guys, I’m using the List View component. Make sure you have used that before commenting.

Sure I have. But with an attitude like that, I will remind myself not to answer a question of you the next time.

Have fun! [import]uid: 5712 topic_id: 7112 reply_id: 25257[/import]