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

Hey, me again!

I just wanted to drop a quick (hummm…) line to say THANK YOU!!! for suggesting I use the Physics engine instead of doing my own object display moves in “enterFrame” and collisions. WHAT a difference!

I not only used the physics to check for collisions but I also provide impulse, and torque the rocks (asteroids) so I do not even have to deal with that in my code.

Now the largest slice of time the Particle Candy process as you can see in this profiler output.

http://s8.postimage.org/6i7sx2gqt/profiler2.jpg

Simply amazing. Thank you again.
I have also couple questions if I may:

1- I noticed that the more I improved my game in term of performance (using physics for instance) the Particle Candy (PC) share of the 20 seconds profiles seems to have increase. Or at least it is now red. I am assuming it is normal…

2- As you can see on the graph above, the PC share seems to be around 80% graphically but the PC time shows only 12 seconds of the total 20 secs. Is it because you only display the top 10 slowest process?

4- Is the profiler works on a MAC as well? It does not work for me (Mac Mini, Lion, Safari) It works like a charm on my laptop PC (vista, Chrome)

3- The line 563 deals with deal with the virtual joystick I am using (in addition of the joystick.lua line 111 and line 43. It seems that when I move the joystick (moves a gun cross on the screen) The process takes the bulk of the process (after PC) I am using the following joystick.lua I found on the code page (byMatthew Pringle) :

http://developer.anscamobile.com/code/joystick

Right now I am assuming it is the stuff I am doing in the joystick phase (moving guncross,…) that slows things down a little. I am curious, did you see something like this in your own game since I believe you are using 2 joysticks! Maybe I am simply using an old joystick code…
In any event, I cannot thank you enough for pointing me in the right direction in term of the physics engine and the time share for the coding in enterframe.

Mo.

ps: Unfortunately, I did not have much time to look into the issue of not being able to display the code line (as you can on the graph above) since I was very busy this last few weeks converting my game for use with the physics engine. Now that it is done and I am back in profiling mode, I will look into the issue again report here.
[import]uid: 49236 topic_id: 17975 reply_id: 74501[/import]

Lemsim,
No problem. The physics engine vs lua movement observation actually came from particle candy. We initially had it in such a way that the projectiles started off as non-physics which turned into physics objects when they were near another object. We ended up getting more FPS using pure physics than the other way around. Surprising yes but it makes sense b/c lua is a scripting language not a number crunching one.

As for your questions

I noticed that the more I improved my game in term of performance (using physics for instance) the Particle Candy (PC) share of the 20 seconds profiles seems to have increase.

yes this is correct. You have done a great job optimizing your code, there is no one section of your code that takes up a lot of time except external libraries. Are you using particle effects just for effects or for your game logic too. Beware, it was not designed to be used for game logic (experience talking).


As you can see on the graph above, the PC share seems to be around 80% graphically but the PC time shows only 12 seconds of the total 20 secs. Is it because you only display the top 10 slowest process?

this can be due to a few reasons.

  1. yes we display the top 10 and there are no other hotspots in your code
  2. Although profiler can look at some C functions that occur under the hood, it does not display the results because quite frankly there is nothing you can do to change it. If for instance the physics engine overhead is taking the rest of the 8 seconds then you will not see it in profiler. We will add the option for a “verbose” mode next update although there will be all sorts of wiered C functions that come up that arent documented that may be confusing.
  3. It might be the case that corona is just idleing during that 8 seconds. if you are running at 30 fps then you have 33ms per frame to do stuff. if you run over this limit then your fps will drop. It could just be the case that your code is taking 80% of this time (like 24ms) and is idleing the other 20%. The best way to find out is run the code on the device with an fps profiler, if the framerate is 30 then you are in good shape.

    4- Is the profiler works on a MAC as well? It does not work for me (Mac Mini, Lion, Safari) It works like a charm on my laptop PC (vista, Chrome)

    Yes it works on mac. However due to security restrictions Mac does not allow us to launch the html file directly from corona. Rather you will have to navigate to your project sandbox document directory and open it. Once you have opened it you can just refresh the page to view a new profiler result.


The line 563 deals with deal with the virtual joystick I am using (in addition of the joystick.lua line 111 and line 43. It seems that when I move the joystick (moves a gun cross on the screen) The process takes the bulk of the process (after PC) I am using the following joystick.lua I found on the code page (byMatthew Pringle) :

are you sure about line 563? it only seems to go to 322. We never seemed to have a problem with the joystick code. Your code must be pretty optimized if that even shows up as one of your top 10 profiler results. Assuming you are only polling it once per frame and you are caching the result, you should have no problem. Beware that accessing x and y coordinates from any display object is more expensive than accessing a table value you created so you should cache this if you are using it multiple times.

Hope that helps and let us know if you have any more questions.
-M.Y. Developers

[import]uid: 55057 topic_id: 17975 reply_id: 74510[/import]

Thank you so much for the FAST response. I am so glad the profiler works on the MAC as well! I go back and forward between the pc and mac.

Yes I can see that everytime I use the joystick it shows high on the list of process. Frankly I am not surprise since I did not work on optimizing the code where the joystick is called. They are many things that I do when the player moves the joystick like moving a gun cross, updating a laser beam and so on.

Yes I learned that the hard way that accessing x and y coordinates from any display object is expensive. I am not completely sure about your suggestion to cache them? For instance I tried
[lua]local gunCross = display.newImageRect (imagesPath…“gunCross.png”,56,56)
gunCross.x = 240; gunCross.y = 160


– then later

local function moveGunCross()

local gunCross = gunCross — this is the I cache the gunCross display object

gunCross.x = 240 + dX*240

if gunCross.x <= 0 then gunCross.x = 0 end
if gunCross.x >= 480 then gunCross.x = 480 end



end[/lua]

Is this what you suggesting? The moveGunCross() is called everytime I touch and move the virtual joystick (joystick.onMove = moveGunCross)

In any event, the good news is your profiler! I can simply make a change and then run it right there and see where the bottlenecks are. No more guesses!

Thank you so much for a great product and an even greater support. I appreciate it very much.

Mo
PS: I am very curious about your question:

“Are you using particle effects just for effects or for your game logic too. Beware, it was not designed to be used for game logic (experience talking)”

I “think” I am using PC for effects (to show explosions when there is a collision between two bodies) What do you mean “PC was made for game logic”? I am wondering if you are talking about using the game logic to start and stop the PC update during the game? That will be great to update PC only an emitter is actual emitting particles. Not sure if that actually possible…

[import]uid: 49236 topic_id: 17975 reply_id: 74521[/import]

Caching the X and Y values will help you alot and you can do it like this

local gunCross = display.newImageRect (imagesPath.."gunCross.png",56,56)  
gunCross.x = 240; gunCross.y = 160  
   
..  
..  
   
-- then later  
   
local function moveGunCross()  
   
local gunCross = gunCross --- this is the I cache the gunCross   
display object  
  
gunCross.x = 240 + dX\*240  
  
local gunCrossX, gunCrossY = gunCross.x, gunCross.y --this line is expensive so we cache these in a local variable so we dont have to access it again.  
  
if gunCrossX \<= 0 then gunCross.x = 0 end --use cached copy  
if gunCrossX \>= 480 then gunCross.x = 480 end --use cached copy  
   
...  
....  
   
   
end  

as for the PC question. For space conquest we initially had PC taking care of spawning bullets and we used FX fields for rockets and stuff. This turned out to be a performance disaster. As long as you are using it only for effects then you should be fine. Just make sure to test consistently on the device.
-M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 74526[/import]

Got it! Thank you so much. I understand about the PC and using it for other things than special effects. Fortunately I am only using it for explosions in my game and it seems to work great.

It is sooo much fun to use your profiler software to squeeze the last bit of performance out of my code! I need all the help I can get it since this is a fast pace game.

THANK YOU!

Mo [import]uid: 49236 topic_id: 17975 reply_id: 74532[/import]

Hi! Wanna thank you for a great job! Your Corona profiler helps me to improve the performance of my game dramatically!!! I started from using 22 sec from 25 on PC) and now it 0,8-1,5 sec from 25. SUPER PERFORMANCE BOOST!
And your advises to turn movement from incrementing x/y valuse per frame to physics are great too!
I have 2 questions:

    • is it possible to launch profiler on the device?(i tried, but i get the page with only one block telling, that 25 sec test is passed…and no other info)
    • when do you plan to make updates and to add opportunity to check overall performance(including physics)? cause even if i get 0,8 sec for 25 sec test…i have framedrops (from 60 to 54-56) that are noticable…and i think it can be cause by a lot of physics objects in the frame!

anyway, thank you for a great job! one of the most useful topic and tool ive ever seen on this forum!!! [import]uid: 41345 topic_id: 17975 reply_id: 74696[/import]

for $6.99 I couldn’t resist. I’ll be checking out how this helps my project. I was thinking of making a similar tool, so really looking forward to using it.

update: unfortunately, having problems. “WARNING: Cannot create path for resource file ‘screenGame.lua’ b/c it does not exist.”

I noticed earlier in the thread you asked someone if they were using subdirectories. I am, and heavily rely on them to keep my code organized. Is there an issue with using the profiler along with subdirectories? [import]uid: 49447 topic_id: 17975 reply_id: 74703[/import]

Hi M.Y. Developers,

Can you give an example of switching over from lua to using the physics engine for updating movement of objects? I have a boids simulation that I’ve sped up with your profiler, and I’m wondering if what your suggesting with the physics engine can be applied to it to further speed things up. I already using the caching technique and the translate, rotate, scale functions to speed things up, but I’m wondering if it can go even faster.

Thanks.
[import]uid: 27183 topic_id: 17975 reply_id: 74726[/import]

Cyhiso,
Thank you for your input, it is much appreciated.
Now to address your questions

  1. no it is currently not possible to profile on the device because in order to display the lines we need access to the LUA source code files. Unfortunately these are not available as resource files on the actual device for security purposes, you probably don’t want to be publishing your code on the app store. If there is popular demand we can look into on device profiling, but it will not be as automated as the desktop profiling (ie it will be more intrusive in your code)

  2. expect an update either tomorrow or the day after

Thanks for the support,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 74832[/import]

Producerism,
Sorry for the delay we have been doing some holiday traveling. We are working on the issue and you will have a fix tomorrow or the day after. The problem arises because LUA does not give us the function names, instead it gives us a LUA filename and a linenumber so we must read the lua files directly. We did not rely on placing code in subdirectories so this problem never came up during testing. Our apologies and we will get this fixed asap.
Thanks,
M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 74834[/import]

Don,
The lesson we learned is: use as little lua code as possible. For instance instead of using a translate() every frame like this

local vx, vy, vr = 10,2  
function enterframe(e)  
 myObj:translate(vx,vy)  
 myObj:rotate(vr)  
end  

the code above is more efficient than reading and setting parameters directly but a speedier way would be to turn it into physics objects so the only lua code you need would be during initialization

physics.addBody(myObj)  
myObj:setLinearVelocity(vx,vy)  
myObj.angularVelicity = vr  

this will in effect do the above code segment but with less lua code. Sorry if there are errors but this is how you could do it.

Thank you and let us know if you have any other questions,
M.Y. Developers
[import]uid: 55057 topic_id: 17975 reply_id: 74835[/import]

Thanks. I get the gist. It’s a matter of balancing how often the physics functions are being called for my boids simulation then. [import]uid: 27183 topic_id: 17975 reply_id: 74850[/import]

Hello M.Y. Developers

Ok, I did some tests and cannot seems to figure out why I cannot see the code lines instead of just the lines# It is very strange. If I just start a brand new main.lua and put some image on the screen and rotate it inside a eventFrame I can see the actual code line. Also if I add the profiler code into an example app (for instance the Ansca Air Hockey example, it also works.

Not sure why my game app is not working out. i am using Corona project manager but it does not seems to be a problem since I try copy/past my game into to the desktop and started a simulator and drop the main.lua into it. Unfortunately that did not help. There must something in my code (or my PC) that block the line code verbose mode.

I will try to use my Mac mini to see if that works better. The problem is that do not know where to find that file. It says something like /user/… I am new to the MAC so I am not sure where everything is!! (it does not seems to be under Corona sdk app folder…

I am curious if any user of profiler has the same issue?

I will post what I found here. Do not worry, I still LOVE your app! I was able to improve my app to actually work on ipod 2 gen when I started with an app that only work on ipad2! This is need to have tool. Especially if you are wroking on fast pace game.

Keep up the great work and cannot wait to see the next version. Only one wish: I hope you guys come up with a similar tool for memory leaks!

Mo.

ps: here the test I did with the Ansca example app Air Hockey

http://s12.postimage.org/j0jcgi4v1/profiler3.jpg

As you can see code lines are fully described. [import]uid: 49236 topic_id: 17975 reply_id: 74852[/import]

quick question. It seems that you use Particle Candy in your game but your “live demo” do not seems to show any time taken by PC? I would love to see your game profile if you are willing to share. if you prefer, I can provide my email for a more private look. I just want to compare it to my game which is also a space shooter game.

In any event, thank you sooo much for sharing this tool. People will be crazy not to get it. Especially for the low cost. Actually deep down, I was hoping that nobody will know about it so I can have a secret weapon! ha, ha! I guess people are starting to figure how useful this tool is…poor me…

@boid: Glad you find the tool useful as well. I will love to hear about your experience as well. I am using physics also (at the suggestion here) but I do not see how you can selectively choose to run the physics in your game. Just curious…

Mo [import]uid: 49236 topic_id: 17975 reply_id: 74857[/import]

M.Y.developers,

Looking forward to the update. I really hope this tool will help me optimize my code. Can’t wait for subdirectory support!

update: outstanding, latest update works fine with subdirectories. Thanks for the quick fix! [import]uid: 49447 topic_id: 17975 reply_id: 74946[/import]

Excuse me, but where can i find profiler update download link? ))
[import]uid: 41345 topic_id: 17975 reply_id: 74961[/import]

Cyhiso,
You should have got it in your email. The same place you got the download link when you purchased profiler.
let us know if you got it,
-M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 74962[/import]

Lemsim,
Let us know if the new update fixes your problems. If not then we may need to look at your project files directly to see what is the problem, rest assured we wont distribute it to anyone.

Keep up the great work and cannot wait to see the next version. Only one wish: I hope you guys come up with a similar tool for memory leaks!

Thanks! The profiler code actually has capability of doing line by line memory leak detection as well but currently we are considering how to display this data. We will be making another tool dedicated to memory leak detection in the future, and just like profiler it will pinpoint it to the exact line.


It seems that you use Particle Candy in your game but your “live demo” do not seems to show any time taken by PC? I would love to see your game profile if you are willing to share.

We actually dynamically adjusted the quality of the game by looking at the average FPS over the last 10 or so frames and if it reached below a threshold we turned off Particle candy and replaced the effects with lower performance counterparts. For example, instead of explosions with PC we just placed a white circle. There was so much going on the screen the player didnt notice and PC did not make it to the top 10 slowest functions list.


I was able to improve my app to actually work on ipod 2 gen when I started with an app that only work on ipad2!

That was our experience too. Glad it is working for you!

Let us know if the update works for you. It also has the percentages you suggested.

-M.Y. Developers [import]uid: 55057 topic_id: 17975 reply_id: 74963[/import]

Works like a charm!

1- How do you enable the verbose mode or is it already on? How can you tell?

2- Just for your info I still have the issue of not being able to see the code lines (only the code#) The tests I did yesterday stands with 1.1 so it is something in my code somehow. A quick test app with an image and a rotation with eventFrame works great but for my app I can only see the code# It will be some much easier if I could see the line of codes so I can tell without having to back and forward between code and profiler results. Even more frustrating is that anytime I change something in my code, the code line# changes of course which makes it not much fun.

I will continue looking and testing and get back to you here. Still, I am curious if anybody else who uses Profiler has the same issue?

In any event, thanks a lot for the new version. I love to see those % number!

Mo.
[import]uid: 49236 topic_id: 17975 reply_id: 74965[/import]

Hello,

Thanks for your response. The possibility of a “memory leak profiler” is frankly the best news of the day! I have been struggling for a month on some leaks and still struggling and so a tool like that will be a time savior of the first order!
Can I just send the code to the email I received about version 1.1? (about 8 meg with assets)

Thanks.

Mo [import]uid: 49236 topic_id: 17975 reply_id: 74966[/import]