Corona® Profiler- A Line-by-Line Analysis of Your Code - New Update

It does thank you, I thought PC was referring the the platform he was using which is why I had problems figuring it out. [import]uid: 129450 topic_id: 17975 reply_id: 93483[/import]

Hello Info583,

No Problem. Thank you for trying out Profiler. Please let us know if you have any more questions.

Regards,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 93519[/import]

A little question : I passed to Lion and I can’t find anymore the “/Users/me/Library/Application Support/Corona Simulator/” folder. Actually, I can’t see ‘Library’ folder in the finder. Any clue ? [import]uid: 9328 topic_id: 17975 reply_id: 95105[/import]

Hi

I have a problem with my game and I have tested it with the Corona Profiler. The test dosen’t seem to be good, I think my game is having some big memory leaks. This is my Graphs and my MemoryUsages for the different scenes.

Settings - Scene: 85.759765625 KB - Graph: http://min.us/mxI2EXFYf

Level 1: 71.068359375 KB - Graph: http://min.us/mxI2EXFYf

Play Scene: 127.189453125 KB - Graph: http://min.us/mxI2EXFYf

Menu Scene: 81.712890625 KB - Graph: http://min.us/mxI2EXFYf

I am using Director, as my scene director and I am removing my objects, stop timers and transitions in my class via the “clean = function()”, that Director calls at the end. Can you via the graphs and memoryusage conclude that this is memory leaks and if yes, how can I solve it then?

[import]uid: 122802 topic_id: 17975 reply_id: 95900[/import]

Hello se460,

Thanks for trying out profiler! how long did you run the profiler for? There is always an increase in memory allocation at the beginning of the program so you may just be looking at that portion. Have you tried looking at the global memory usage of your app via just doing a collectgarbage(“count”) command every few seconds? We suggest you do this first to see if the memory keeps increasing, especially between screen changes (ie when you are supposed to clean up.) If you do have a memory leak then you will want to identify when it occurs (ie b/w menu screen and game screen) then start using mode 4. Mode 4 will tell you what tables are increasing between snapshot to snapshot and this will give you an idea where the leaks are coming from. Generally leaks arise from global variables or upvalues (aka static variables).

Thanks,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 96733[/import]

Hello All,

Please download the new update v 1.4. We made a critical bug fix that prevented runtime errors from showing up in the console during a debug session. Also we fixed some path naming issues that prevented ‘-’ from being used in the path.

Thanks,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 96823[/import]

Hi M.Y. Developers

Thank you for your response, I really appreciate it. I ran the profiler, until I got the message in the console, saying that large positive memory usage numbers could be a memory leak and until it opened the time line in the browser.
I have tried to run a collectgarbage(“count”) and here is the memory usage information that I have got from the console.
Start: Menu = 186.442-186.470 KB
Menu -> Play = 227.639 KB
Play -> Menu = 199.965 KB
Menu -> Options = 204.308 KB
Options -> Menu = 204.684 KB
Second time going from Menu -> Play = 229.523 KB
and from Play -> Menu = 201.000 KB

Is this indicating a memory leak?
I hope you understand what I mean with the above.
Thank you in advance :slight_smile:

[import]uid: 122802 topic_id: 17975 reply_id: 97565[/import]

@se460,
Sorry about the delay. There may indeed be a slight memory leak but try doing this sequence instead
Menu -> Play
Play -> Menu
Menu -> Play
Play -> Menu
Menu -> Play
Play -> Menu

You will get a steady state this way. The reason you cant just do it once is b/c things may still be initializing until the 3rd time through. See if you get a consistent increase in memory during the last few times. If so you have a leak. To find out what is causing the leak just put a profiler.diffSnapshot() function call between the transitions. So something like this

Menu -> Play
Play -> Menu
profiler.diffSnapshot()
Menu -> Play
Play -> Menu
profiler.diffSnapshot()
Menu -> Play
Play -> Menu
profiler.diffSnapshot()
Menu -> Play
Play -> Menu
profiler.diffSnapshot()
Menu -> Play
Play -> Menu

If there was no leak you would expect the diffSnapshot() to report 0 increase in any lua table if everything was cleaned properly. If there is a leak, the diffSnapshot will tell you exactly what lua table(s) is/are causing the problem. You may repeat the procedure for any combination of screen transitions but try to keep it consistent for experimental control.

Regards,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 98120[/import]

Hi!

How to I get the 1.4 version?

also, I’m trying to figure out if I can improve the performance of this

[lua] for y = 1, mMap.yTilesInView do
local ny = spritemap[y] – display group holding newImageGroups that in turn holds sprites
local yy = ty + y
for x = 1, mMap.xTilesInView do
local xx = tx + x
local t = ny[x] – specific sprite tile
t.rotation = mTiles[xx][yy].rotation – mTiles is a table that holds tables in tables
if(xx >= 0 and xx < mMap.xTiles and yy >= 0 and yy < mMap.yTiles) and t.frame ~= mTiles[xx][yy].sprite then
t:setFrame(mTiles[xx][yy].sprite)
end
end
end [/lua]

I’ve managed to lower it from 370ms to 270ms in a 10 sec recording but since this is the most taxing part of my game I would like to improve it further.

Line 6,7,8 are currently the most taxing.
Regards info583 [import]uid: 129450 topic_id: 17975 reply_id: 98725[/import]

Maybe this could reduce it a few more ms…

[lua]for y = 1, mMap.yTilesInView do
local ny = spritemap[y] – display group holding newImageGroups that in turn holds sprites
local yy = ty + y
for x = 1, mMap.xTilesInView do
local xx = tx + x
local refTile = mTiles[xx][yy] – mTiles is a table that holds tables in tables
local t = ny[x] – specific sprite tile
t.rotation = refTile.rotation
if(xx >= 0 and xx < mMap.xTiles and yy >= 0 and yy < mMap.yTiles) and t.frame ~= refTile.sprite then
t:setFrame(refTile.sprite)
end
end
end [/lua] [import]uid: 70847 topic_id: 17975 reply_id: 98727[/import]

Hello info583,
How to I get the 1.4 version?
You should have gotten an email from e-junkie with the download details. Did you not?

took some bits from igemar, great advice!

 local ny,yy,xx,t,refTile --do not "overlocalize" variables   
 for y = 1, mMap.yTilesInView do  
 ny = spritemap[y] -- display group holding newImageGroups that in turn holds sprites  
 yy = ty + y   
 for x = 1, mMap.xTilesInView do   
 xx = tx + x   
 t = ny[x] -- specific sprite tile   
 refTile = mTiles[xx][yy] -- mTiles is a table that holds tables in tables   
 t.rotation = refTile.rotation --can you replace this with incremental t:rotate(...)  
 if(xx \>= 0 and xx \< mMap.xTiles and yy \>= 0 and yy \< mMap.yTiles) and t.frame ~= refTile.sprite then   
 t:setFrame(refTile.sprite)   
 end  
 end  
 end   

would like to add some things:

  1. Do not over-localize. Try putting locals outside of loops.
  2. can you use t:rotation(dr) instead?
  3. is it possible to turn mTiles[xx][yy] into an associative 1D array (ie mTiles[xx…yy]). Try to linearize this somehow.
  4. can you switch the order of the arrays so you can cache mtiles[xx] as well? Something like:

local ny,yy,xx,t,refTile,refTileXX --do not "overlocalize" variables for x = 1, mMap.xTilesInView do xx = tx + x refTileXX = mTiles[xx]; --cache this here for y = 1, mMap.yTilesInView do ny = spritemap[y] -- display group holding newImageGroups that in turn holds sprites yy = ty + y t = ny[x] -- specific sprite tile refTile =refTileXX[yy] -- mTiles is a table that holds tables in tables t.rotation = refTile.rotation --can you replace this with incremental t:rotate(...) if(xx \>= 0 and xx \< mMap.xTiles and yy \>= 0 and yy \< mMap.yTiles) and t.frame ~= refTile.sprite then t:setFrame(refTile.sprite) end end end
Regards,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 98923[/import]

Thanks for the replies.

I didn’t buy Profiler myself, it was purchased on my request by the company I work in and is since registered on a company mail which I don’t have access to, going to check with the manager as soon as he gets back but it’ll probably be there :slight_smile:

Regarding the performance tips you gave I’ve tried all but number 3 (need to read up on associative arrays) and 4 (going to try this when I get the time), strangely enough it all resulted in a decrease in performance ending up with 320ms. I did a reference test before I made any changes that resulted in 260ms. [import]uid: 129450 topic_id: 17975 reply_id: 99762[/import]

@info583,

how about this one?

local xx,refTileXX --do not "overlocalize" variables   
for x = 1, mMap.xTilesInView do  
 xx = tx + x   
 refTileXX = mTiles[xx]; --cache this here  
 local ny,yy,t,refTile  
 for y = 1, mMap.yTilesInView do   
 ny = spritemap[y] -- display group holding newImageGroups that in turn holds sprites  
 yy = ty + y   
 t = ny[x] -- specific sprite tile   
 refTile =refTileXX[yy] -- mTiles is a table that holds tables in tables   
 t.rotation = refTile.rotation --can you replace this with incremental t:rotate(...)  
 if(xx \>= 0 and xx \< mMap.xTiles and yy \>= 0 and yy \< mMap.yTiles) and t.frame ~= refTile.sprite then   
 t:setFrame(refTile.sprite)   
 end  
 end  
end   

Regards,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 99805[/import]

Thanks again for the quick reply, will get back to you when I have the chance to try it out. [import]uid: 129450 topic_id: 17975 reply_id: 100523[/import]

Ok, this is what I got right now and running my test I still get around 260ms which makes me believe this is as far as it goes. The most taxing lines now is 7,8 and 11.

[lua]local ny,yy,xx,t
for y = 1, mMap.yTilesInView do
ny = spritemap[y]
yy = ty + y
for x = 1, mMap.xTilesInView do
xx = tx + x
t = ny[x]
if t.rotation ~= mTiles[xx…yy].rotation then
t.rotation = mTiles[xx…yy].rotation
end
if(xx >= 0 and xx < mMap.xTiles and yy >= 0 and yy < mMap.yTiles) and t.frame ~= mTiles[xx…yy].sprite then
t:setFrame(mTiles[xx…yy].sprite)
end
end
end[/lua] [import]uid: 129450 topic_id: 17975 reply_id: 100562[/import]

try caching xx…yy into a variable. The concatenation and string conversion takes time but the associative array will save time in the long run.

local ny,yy,xx,t for y = 1, mMap.yTilesInView do ny = spritemap[y] yy = ty + y for x = 1, mMap.xTilesInView do xx = tx + x local key = xx..yy t = ny[x] if t.rotation ~= mTiles[key].rotation then t.rotation = mTiles[key].rotation end if(xx \>= 0 and xx \< mMap.xTiles and yy \>= 0 and yy \< mMap.yTiles) and t.frame ~= mTiles[key].sprite then t:setFrame(mTiles[key].sprite) end end end [import]uid: 55057 topic_id: 17975 reply_id: 100583[/import]

Changed it to your example and I came up with a ot question.

How come writing for example mTiles[5050] doesn’t work but x = 50, y = 50 and mTiles[x…y] does? Isn’t it the same thing? [import]uid: 129450 topic_id: 17975 reply_id: 101248[/import]

Also, just noticed that the way I’m using associtive arrays atm messes up the app.

For example, x = 5 y = 21 x…y = 521, x = 52 y = 1 x…y = 521 meaning tiles get overwritten. Don’t know how to fix this since I use x…y in a very lot of places in my app.

I was thinking of adding a symbol between x and y which would mean something like x…":"…y.

Would this make the concatenation calculation heavier? [import]uid: 129450 topic_id: 17975 reply_id: 101601[/import]

Hello info,

It all depends. The benefit of using the associative array is it will reduce the amount of lookups you will need to do. x[5050] is not the same as x[“5050”] (this is what happens when you do the concat. Is the code faster than the first implementation? If the code is significantly faster with the change then it will be worth pursuing.

How often are you running this routine? You probably do not need to do this every frame or you can even interlace even/odd lines between frames.

Regards,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 101613[/import]

Ah I see, didn’t realize it was converted to a string thanks.

Can’t say that I saw any noticeable change in performance though I only tested it with profiler and not on device.

For now the game runs at around 20 fps on device which seems playable though it’s hard to tell since I don’t have any real gameplay in yet.

The routine is run every time I move the camera and when “miners” digs out a tile. I’m planning to change the last one so that only the affected tile gets updated.

I’m using this technique in order to have really big maps at the cost of updating a screen full of sprites and a snapping camera.

But you don’t think adding “:” to the concact would decrease performance? Since this option would be easier to implement rather than going back to using 2d arrays. [import]uid: 129450 topic_id: 17975 reply_id: 101617[/import]