Nested Display Groups = poor performance . Getting unregistered touch events (plug-in Play)

From what i have tracked down display groups are bad and nested display groups are nasty. The strange thing is that there are no touch events and the FPS drops below 10 on touch. << on the Simulator!

Nested Displays kill the render?
Nested Displays register touch events?

-Darkmod

[code]-- FPS ---------------------------------------------
PerformanceOutput = {}; PerformanceOutput.mt = {};
PerformanceOutput.mt.__index = PerformanceOutput;

– LOCAL VARS ---------------------------------------
local screenW, screenH = display.contentWidth, display.contentHeight
local prevTime = 0;
local maxSavedFps = 30;
----------------------------------------------------------------------------- FPS Start
local function createLayout(self)
local group = display.newGroup(); group.x = group.x + 90; group.y = group.y + 15;group:scale(1.5,1.5);
self.memory = display.newText(“0/10”,20,0, Helvetica, 15);
self.framerate = display.newText(“0”, 30, self.memory.height, “Helvetica”, 20);
local background = display.newRect(-50,0, 175, 50);
self.memory:setTextColor(255,255,255);
self.framerate:setTextColor(255,255,255);
background:setFillColor(0,0,0);
group:insert(background);
group:insert(self.memory);
group:insert(self.framerate);
return group;
end

local function minElement(table) local min = 10000;
for i = 1, #table do
if(table[i] < min) then
min = table[i];
end;
end;
return min;
end

local function getLabelUpdater(self)
local lastFps = {};
local lastFpsCounter = 1;
return function(event)
local curTime = system.getTimer(); local dt = curTime - prevTime;
prevTime = curTime; local fps = math.floor(1000/dt);
lastFps[lastFpsCounter] = fps; lastFpsCounter = lastFpsCounter + 1;
if(lastFpsCounter > maxSavedFps) then lastFpsCounter = 1; end
local minLastFps = minElement(lastFps);
self.framerate.text = “FPS: “…fps…”(min: “…minLastFps…”)”;
self.memory.text = “Mem: “…(system.getInfo(“textureMemoryUsed”)/1000000)…” mb”;
end
end
local instance = nil;

function PerformanceOutput.new()
if(instance ~= nil) then return instance; end
local self = {};setmetatable(self, PerformanceOutput.mt);
self.group = createLayout(self);
Runtime:addEventListener(“enterFrame”, getLabelUpdater(self));
instance = self;return self;
end

local maxSavedFps = 60;PerformanceOutput.new();
---------------------------------------------------- end FPS
– Create 2000 nested Display Groups insert 1 obj-------------

local display_main = display.newGroup()
local pos = {}
pos = {x=200, y=200, num=10}
local display_nest ={}
for i=1, 2000 do
display_nest[i] = display.newGroup()
if i==1 then
display_main:insert(display_nest[i])
else
display_nest[i - 1]:insert(display_nest[i])
end
end
print(display.contentWidth)
local myRec = display.newRect(display.screenOriginX + (display.contentWidth/5.5), display.contentHeight/4, 200, 200)
myRec:setFillColor(255, 0, 0,80); myRec:setStrokeColor(255, 255, 255);myRec.strokeWidth =2;
myRec.text = display.newText(“I Have NO Touch Events!”,myRec.x - 160,myRec.y - 140, Helvetica, 27);
myRec.text2 = display.newText(“TOUCH ME”,myRec.x - 95,myRec.y - 30, Helvetica, 32);
display_nest[2000]:insert(myRec)

[import]uid: 7177 topic_id: 15918 reply_id: 315918[/import]

Can anyone confirm this? [import]uid: 7177 topic_id: 15918 reply_id: 59408[/import]

Hey Darkmod,

Can you file this as a bug including code to replicate and post the # here, please?

Peach :slight_smile: [import]uid: 52491 topic_id: 15918 reply_id: 59463[/import]

Its filed now #2698

-Darkmod [import]uid: 7177 topic_id: 15918 reply_id: 59492[/import]

Is this bug being addressed? It is causing major performance issues in our current project on the 3GS. [import]uid: 7531 topic_id: 15918 reply_id: 60157[/import]

Hey peach pellen. any word on this bug? [import]uid: 7177 topic_id: 15918 reply_id: 65760[/import]

Hey there,

To follow up on the bug, you can view it in FogBugz :slight_smile:

Peach [import]uid: 52491 topic_id: 15918 reply_id: 65873[/import]

How do we “view it in FogBugz?” I’d like to see what’s happening with this issue as well.

Thanks [import]uid: 1654 topic_id: 15918 reply_id: 70227[/import]

I believe this is the correct link; http://bugs.anscamobile.com/

Peach :slight_smile: [import]uid: 52491 topic_id: 15918 reply_id: 70269[/import]

Not much to see on FogBugz. I see that its is open and that’s about it. Its defiantly not! on the priority page. The bug is probably tied to the core pipeline event/render system.

From what i can tell Corona has a single pipeline that goes though every object on the screen. Meaning if you had 2000 empty display groups. It goes thru every object to see if it needs to be rendered and or if it has any attached touch events. In return, slows down the fps x2 if you are touching the screen. Ideally Corona need array lists holding objects that need to be rendered and an array list that holds touch events. This would probably improve all projects especially Lime or anyone that has 50 or move objects on the screen.

I would like to see this get more attention. [import]uid: 7177 topic_id: 15918 reply_id: 70724[/import]

Hi Darkmod,

I understand your concerns and will bring them up in our next meeting.

Peach :slight_smile: [import]uid: 52491 topic_id: 15918 reply_id: 70740[/import]

Hi again Darkmod,

Can you give me a bit more information on how you would utilize a hierarchy of groups that is 2000 levels deep in one of your projects?

Thanks,
Peach :slight_smile: [import]uid: 52491 topic_id: 15918 reply_id: 70919[/import]

Hey there Peach, did my reply make any sense. Let me know if you need anymore info.

Thx, Darkmod [import]uid: 7177 topic_id: 15918 reply_id: 71799[/import]

Hey Darkmod,

I’ve passed on your info and code to the team, although because there is currently a code freeze waiting on the next stable release (very soon!) it may take a little to hear back.

Peach :slight_smile: [import]uid: 52491 topic_id: 15918 reply_id: 71812[/import]

I would never use a nested group 2000 deep. I did that in the example above to show the slowdown in the simulator. The core problem is that every tick corona checks every object for events. Below I have one display group with 500 objects with NO TOUCH EVENTS. Run the code and you can see the FPS drop to 10ish on the simulator. On a second gen IPhone it would drop to 1. I’m sure one of your programs can optimize what is handled in the per frame tick. Instead of scanning thru every object it would check an array list of registered events. I have a feeling the render works the same way :frowning:

Thanks peach,
[lua]-- FPS ---------------------------------------------
PerformanceOutput = {}; PerformanceOutput.mt = {};
PerformanceOutput.mt.__index = PerformanceOutput;

– LOCAL VARS ---------------------------------------
local screenW, screenH = display.contentWidth, display.contentHeight
local prevTime = 0;
local maxSavedFps = 30;
----------------------------------------------------------------------------- FPS Start
local function createLayout(self)
local group = display.newGroup(); group.x = group.x + 90; group.y = group.y + 15;group:scale(1.5,1.5);
self.memory = display.newText(“0/10”,20,0, Helvetica, 15);
self.framerate = display.newText(“0”, 30, self.memory.height, “Helvetica”, 20);
local background = display.newRect(-50,0, 175, 50);
self.memory:setTextColor(255,255,255);
self.framerate:setTextColor(255,255,255);
background:setFillColor(0,0,0);
group:insert(background);
group:insert(self.memory);
group:insert(self.framerate);
return group;
end

local function minElement(table) local min = 10000;
for i = 1, #table do
if(table[i] < min) then
min = table[i];
end;
end;
return min;
end

local function getLabelUpdater(self)
local lastFps = {};
local lastFpsCounter = 1;
return function(event)
local curTime = system.getTimer(); local dt = curTime - prevTime;
prevTime = curTime; local fps = math.floor(1000/dt);
lastFps[lastFpsCounter] = fps; lastFpsCounter = lastFpsCounter + 1;
if(lastFpsCounter > maxSavedFps) then lastFpsCounter = 1; end
local minLastFps = minElement(lastFps);
self.framerate.text = “FPS: “…fps…”(min: “…minLastFps…”)”;
self.memory.text = “Mem: “…(system.getInfo(“textureMemoryUsed”)/1000000)…” mb”;
end
end
local instance = nil;

function PerformanceOutput.new()
if(instance ~= nil) then return instance; end
local self = {};setmetatable(self, PerformanceOutput.mt);
self.group = createLayout(self);
Runtime:addEventListener(“enterFrame”, getLabelUpdater(self));
instance = self;return self;
end

local maxSavedFps = 60;PerformanceOutput.new();
---------------------------------------------------- end FPS
– Create 2000 nested Display Groups insert 1 obj-------------

local display_main = display.newGroup()
local pos = {}
pos = {x=200, y=200, num=10}

for i=1, 500 do
local myRec = display.newRect(display.screenOriginX + (display.contentWidth/5.5), display.contentHeight/4, 200, 200)
myRec:setFillColor(255, 0, 0,80); myRec:setStrokeColor(255, 255, 255);myRec.strokeWidth =2;
display_main:insert(myRec)
end

[import]uid: 7177 topic_id: 15918 reply_id: 70929[/import]