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

Hello Info583,


game runs at around 20 fps

Anything less than 30 at this stage is worth optimizing. When you are running less than 30 fps it means you are already running at maximum capacity, any extra processing will lead to a decrease in fps. Also. do you have it set to 30fps or 60fps?

The routine is run every time I move the camera
How about just updating the edges? Are you doing this every frame? try doing it every other frame, or over 3 frames, or until it becomes noticeable.


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.
The link goes to the ansca homepage.


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.
We will have to try it and see, you will get more performance gains as you add more dimensions. It probably like a O(log(n)) vs a O(n) type scenario.

The main take home point is if you are doing something on every single frame event, chances are you are doing it too often. In our space conquest game we ended up running the AI look every 20 frames, the camera loop every 4 frames, the weapons timer every 8 frames. In fact the only thing we had running every frame was the controls because this needed to be responsive as possible.

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

do you have it set to 30fps or 60fps?

I have it set at 60 fps atm.

How about just updating the edges? Are you doing this every frame?

This would be great, however it wouldn’t work. Each time the view “snaps” all tiles has to be updated since everything has to move in conjunction with each other.

The link goes to the ansca homepage.

Ops! Sorry, this should work http://developer.anscamobile.com/forum/2011/01/29/object-culling-render-process-when-not-content-area#comment-26658 post #11

Thanks a lot for all your feedback M.Y. Developers, your customer service is priceless!

[import]uid: 129450 topic_id: 17975 reply_id: 101788[/import]

Hello info,


I have it set at 60 fps atm.

Please set this to 30 fps. That will put your game around 40fps giving you a 10fps reserve to do other stuff. 7ms extra is a long time and you can squeeze in other extra features (ie particle effects, sound effects, etc)

Let us know how things are working out.

Regards,
M.Y. Developers

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

I changed it to 30 fps and reduced the number of sprites I update which improved the performance significantly, this however limits the maximum zoom, I probably wouldn’t have any problems with this but the way the camera acts is really starting to get to me (it feels and looks bad since the smallest increment is the width or height of a tile).

So I’m thinking of doing some sort of culling system maybe by making several display groups each consisting of an area with 20 by 20 tiles. The problem is that I don’t know how this would help me since the .isVisible variable doesn’t seem to do much for performance, I remember creating a large number of tiles and then hiding all of them which didn’t do anything really.

Do you guys know how an efficient culling system can be achieved?

Thanks in advance
// info583

EDIT: Just realized how I can make the camera smooth, would still be interesting to know if there’s an alternative though,since the zoom is still limited. [import]uid: 129450 topic_id: 17975 reply_id: 102115[/import]

@info,


Do you guys know how an efficient culling system can be achieved?

Wasn’t this done in a daily build sometime? or is this still on the road-map? Not sure but it might be already done for you behind the scenes.

Here is what you could do for a smooth tile based scrolling. Suppose the screen size is 30x40 tiles. Just place a 1 tile border around it so you will get 32x42. Now to scroll just move the entire display group around and when you get to the edge of the border you will have to snap the group back to the center and replace all the tiles to their new location. This way you should be able to get smooth scrolling but without any culling necessary. And you wont have to load the size of the map, just the size of the screen. In theory the map could be infinite.

Regards,
M.Y. Developers

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

Wasn’t this done in a daily build sometime? or is this still on the road-map? Not sure but it might be already done for you behind the scenes.

I think they added it with the new sprite API but I couldn’t notice any difference.

Here is what you could do for a smooth tile based scrolling. Suppose the screen size is 30x40 tiles. Just place a 1 tile border around it so you will get 32x42. Now to scroll just move the entire display group around and when you get to the edge of the border you will have to snap the group back to the center and replace all the tiles to their new location. This way you should be able to get smooth scrolling but without any culling necessary. And you wont have to load the size of the map, just the size of the screen. In theory the map could be infinite.

This is exactly what I realized yesterday :slight_smile: The only problem left is that the max zoom out distance is limited, hopefully I can optimize it well enough to be satisfactory.

Thanks for all the help M.Y.developers, you guys have saved me so much trouble!

Regards
info583 [import]uid: 129450 topic_id: 17975 reply_id: 102237[/import]

How do I use the profiler to find out which part is giving me the memory leak? [import]uid: 116264 topic_id: 17975 reply_id: 103710[/import]

Hello Willjhoward,
First of all you need to determine if you really do have a memory leak and it is not just due to allocation. Most leaks occur during screen changes and between levels of games (ie when you have to deallocate the scene and reinstantiate it.)

For instance, suppose you have screen A and screen B. You would want to measure the memory between screen changes and go back and forth many times so you can determine if there is a steady memory leak.

A->B->A->B->A…

If there is a leak you will see it given enough screen transitions.

Next you will want to use mode 4 and place a diffSnapshot at every screen change. Then you repeat the process and Profiler will point you to the lua table that is causing the leak.

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

I am pretty sure I have a leak, as when I am on the menu screen of the game, the memory is at 120, but when I go to level one and then back to the menu scren, the memory is at 180. I have used mode 4 of the profiler and it shows that everything on level one gets deleted when I return to the menu. Any suggestions? [import]uid: 116264 topic_id: 17975 reply_id: 103968[/import]

@M.Developers.

Hi guys, it has been awhile since I had time to profile my upcoming game (I know, I know…) but I just suggested the profiler here;

http://developer.anscamobile.com/forum/2012/05/26/ghosts-vs-monsters-memory-leak#comment-110697

And then I was thinking that the leak neil16 is talking about could be a very good case study for the profiler! You could use that free code to show people how you will go about finding and cleaning memory leaks.

Obviously just a suggestion and as time permit. With all the wonderful add-ons you guys have on the stove, I am not sure how you could add this on top :slight_smile:

Can’t wait to do some more memory profiling soon!

Mo
(LairdGames) [import]uid: 100814 topic_id: 17975 reply_id: 110698[/import]

Thanks for pointing me here mo, I’ve just had a good run through, obviously I second the call to analyse the ghosts vs monsters code!

I’ve tried using profiler, but I don’t think I have a leak as such, I load a scen, return to menu and I have an increase, if I then reload the same scene and back to menu, I am not experiencing any further rises, but I am always gaining memory usage from every new scene that I start. [import]uid: 125592 topic_id: 17975 reply_id: 110723[/import]

I’m trying to launch Profiler on Android devices, but it fails with exception:

[blockcode]01-06 10:18:20.944: W/System.err(986): java.io.FileNotFoundException: main.lua
01-06 10:18:20.954: W/System.err(986): at android.content.res.AssetManager.openAsset(Native Method)
01-06 10:18:20.954: W/System.err(986): at android.content.res.AssetManager.open(AssetManager.java:313)
01-06 10:18:20.954: W/System.err(986): at com.ansca.corona.NativeToJavaBridge.externalizeAsset(NativeToJavaBridge.java:456)
01-06 10:18:20.954: W/System.err(986): at com.ansca.corona.NativeToJavaBridge.callExternalizeResource(NativeToJavaBridge.java:499)
01-06 10:18:20.954: W/System.err(986): at com.ansca.corona.JavaToNativeShim.nativeRender(Native Method)
01-06 10:18:20.954: W/System.err(986): at com.ansca.corona.JavaToNativeShim.render(JavaToNativeShim.java:100)
01-06 10:18:20.954: W/System.err(986): at com.ansca.corona.Controller.onDrawFrame(Controller.java:235)
01-06 10:18:20.954: W/System.err(986): at com.ansca.corona.CoronaRenderer.onDrawFrame(CoronaRenderer.java:74)
01-06 10:18:20.954: W/System.err(986): at android.opengl.derived.SwapGLSurfaceView$GLThread.guardedRun(SwapGLSurfaceView.java:949)
01-06 10:18:20.954: W/System.err(986): at android.opengl.derived.SwapGLSurfaceView$GLThread.run(SwapGLSurfaceView.java:809)

01-06 10:18:20.954: I/Corona(986): Lua Runtime Error: lua_pcall failed with status: 2, error message is: bad argument #1 to ‘sub’ (string expected, got nil)
[/blockcode]

If I comment profiler.startProfiler() all works fine. [import]uid: 131398 topic_id: 17975 reply_id: 111366[/import]

Hello Sakharov,

Sorry but it is not possible to profile on a device. This is simply due to the fact that the actual lua source files are not loaded onto the device so unfortunately it is not possible to profile them. So when profiler looks for the source file main.lua you get the

java.io.FileNotFoundException: main.lua  

Please profile on the simulator. Any slow code will also be slow on the simulator so you will still be able to identify hotspots and fix them

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

Just going to say that I picked this up tonight and wow, Profiler is a really slick and handy tool. Surprised this isn’t on the main Corona apps list - it’s that useful. [import]uid: 41884 topic_id: 17975 reply_id: 116949[/import]

I believe I have a major memory leek, that stems from transitions between screens. As you can see MemUsage just keeps growing for each transition:

From screen A:
MemUsage: 381.1025390625
TexMem: 2.342912

to screen B:
MemUsage: 426.451171875
TexMem: 2.441216

Back to Screen A:
MemUsage: 428.0859375
TexMem: 2.342912

to screen C
MemUsage: 512.357421875
TexMem: 7.159808

And back to Screen A:
MemUsage: 611.0771484375
TexMem: 7.929856

I tried removing all my display objects and variables manualle, but the leek persists. So I bought your tool, hoping it would show me wich tables where not beeing removed properly. I can’t seem to get the Memory Timeline Results Screen to show. How do I get it shown ? Running profileTime.html only shows me the Profiler Results Screen. I tried
profiler.startProfiler({time = 10000, delay = 1000, mode=4});
and profiler.diffSnapshot() just before and after screen transitions. What am I missing?
[import]uid: 128197 topic_id: 17975 reply_id: 119504[/import]

I believe I have a major memory leek, that stems from transitions between screens. As you can see MemUsage just keeps growing for each transition:

From screen A:
MemUsage: 381.1025390625
TexMem: 2.342912

to screen B:
MemUsage: 426.451171875
TexMem: 2.441216

Back to Screen A:
MemUsage: 428.0859375
TexMem: 2.342912

to screen C
MemUsage: 512.357421875
TexMem: 7.159808

And back to Screen A:
MemUsage: 611.0771484375
TexMem: 7.929856

I tried removing all my display objects and variables manualle, but the leek persists. So I bought your tool, hoping it would show me wich tables where not beeing removed properly. I can’t seem to get the Memory Timeline Results Screen to show. How do I get it shown ? Running profileTime.html only shows me the Profiler Results Screen. I tried
profiler.startProfiler({time = 10000, delay = 1000, mode=4});
and profiler.diffSnapshot() just before and after screen transitions. What am I missing?
[import]uid: 128197 topic_id: 17975 reply_id: 119504[/import]

@M.Y DEVELOPERS

I was wondering how to cut and past the result on the web page (mode 4) Every time I try to cut and past some of all the page, it highlight but then the highlight goes away and copy do not copy anything.

The reason I want do this is to show part of the result on this forum. I basically trying to copy and past but the web page seems to reload by itself even if I stop the simulator and save the page?

I am using the windows PC but I think it is the same on Safari Mac.

Any ideas / suggestions?

Mo

Ps: I am in love with Glider! [import]uid: 100814 topic_id: 17975 reply_id: 126760[/import]

Hello Mo,

Yeah the page refreshes itself as new results become available. Perhaps you can hit ctrl-a and ctrl-c in quick succession to copy the entire page. Glad you are liking profiler and Glider!

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

@M.Y DEVELOPERS

I was wondering how to cut and past the result on the web page (mode 4) Every time I try to cut and past some of all the page, it highlight but then the highlight goes away and copy do not copy anything.

The reason I want do this is to show part of the result on this forum. I basically trying to copy and past but the web page seems to reload by itself even if I stop the simulator and save the page?

I am using the windows PC but I think it is the same on Safari Mac.

Any ideas / suggestions?

Mo

Ps: I am in love with Glider! [import]uid: 100814 topic_id: 17975 reply_id: 126760[/import]

Thanks! I will try that and report here.

Mo. [import]uid: 100814 topic_id: 17975 reply_id: 126973[/import]