Optimisation Tips

Quick question for the Corona experts out there, is there any advantage to localising an external function call beyond localising the return value?

i.e is

local highestCombo = getHighestCombo
highestCombo(comboMultiplierArray)

better then

local highestCombo = getHighestCombo(comboMultiplierArray)

Any help would be appreciated, I can’t imagine there being much of a performance hit, but knowing for certain would be very handy.

Many thanks,

[import]uid: 33275 topic_id: 22840 reply_id: 322840[/import]

If this is an external function (ie its a function defined in another file) then it might have a really slight advantage. If its all local to the current lua file then i can’t see it making any worthwhile difference [import]uid: 84637 topic_id: 22840 reply_id: 91247[/import]

Hi Danny, thanks for the help.

I’m just trying to optimise like crazy - managed to ensure there’s no memory leaks on the textureMem side of things, but system memory seems to jump every time I play a new game.

I was hoping it was because external function calls hadn’t been localised and perhaps there were still references in the global scope - otherwise I’m all out of ideas.

Thanks again for the help… [import]uid: 33275 topic_id: 22840 reply_id: 91253[/import]

It is normal for memory usage to increase a bit upon changing scenes etc. It does get removed/cleared, it’s just the lua garbage collector waiting to be run.

Perfectly normal to see a 50>60kb (roughly) increase every scene, it does get collected, just not immediately [import]uid: 84637 topic_id: 22840 reply_id: 91255[/import]

Thanks again for the info - but I’m getting results like this:

START DIRECTOR

Total Play Time: 0
SCALE_X SCALE_Y 0.5 0.5

MAIN
memUsage = 108.026 KB
texMemUsage = 0.000 MB


MENU
memUsage = 134.012 KB
texMemUsage = 0.000 MB


END MENU
memUsage = 346.256 KB
texMemUsage = 8.875 MB


MENU - LOADSTAGE1
memUsage = 344.671 KB
texMemUsage = 5.750 MB


START LOADSTAGE1
memUsage = 443.851 KB
texMemUsage = 0.000 MB


LOADSTAGE 1 - STAGE 1
memUsage = 509.789 KB
texMemUsage = 0.000 MB

CREATING BACKGROUND
0

STAGE 1 LETS START
memUsage = 539.780 KB
texMemUsage = 1.250 MB

iSTAGE: 1

STAGE - CUSTOMER
memUsage = 539.780 KB
texMemUsage = 1.250 MB


CUSTOMER - STAGE
memUsage = 558.098 KB
texMemUsage = 3.250 MB


SUSHI
memUsage = 557.973 KB
texMemUsage = 3.250 MB


SUSHI - THESTAGE
memUsage = 574.727 KB
texMemUsage = 3.250 MB


SCORE
memUsage = 574.285 KB
texMemUsage = 3.250 MB


SCORE - THESTAGE
memUsage = 585.244 KB
texMemUsage = 4.774 MB


END STAGE 1 CREATE
memUsage = 632.148 KB
texMemUsage = 14.024 MB

… GAMEPLAY LOGS …


STAGE 1 - GAME OVER
memUsage = 683.330 KB
texMemUsage = 8.000 MB


STAGE - GAMEOVER
memUsage = 683.076 KB
texMemUsage = 8.000 MB


RETURNING TO MENU


MENU
memUsage = 693.134 KB
texMemUsage = 0.000 MB


END MENU
memUsage = 697.358 KB
texMemUsage = 8.875 MB

As you can see systemMemory has almost doubled by the time I’ve returned to the menu screen after one play-through - subsequent games don’t increase by as much, but still adding 50KB each play-through.

So I’m thinking, somewhere I’ve done something pretty wrong…

Thanks again for the help…
[import]uid: 33275 topic_id: 22840 reply_id: 91257[/import]

I’m not 100% sure it’s your fault.

I created scenemanager to use instead of director as i was getting memory leaks : http://code.google.com/p/scene-manager/downloads/list

You could try that (instead of director) and see if those numbers improve.

And if that doesn’t help you could try using storyboard instead.

If you try those two and your still getting more or less the same numbers then it’s more likely your code not cleaning something than the class that handles the scene changes.

Try them and let me know how you get on :slight_smile: [import]uid: 84637 topic_id: 22840 reply_id: 91260[/import]

Hi Danny, thanks for the links - I really appreciate your advice.

Could you just confirm one thing for me, and I won’t pester you any longer - promise :slight_smile:

If I make a call to an external function ala

game.function1()

Would that call reside in the global score, i.e would that be hanging around when I’ve played through the game and returned to the menu screen, soaking up system memory?

I’m just going through my code - thinking that such calls should be localised using the technique up above?

Many thanks, [import]uid: 33275 topic_id: 22840 reply_id: 91267[/import]

There is no harm in localizing them if you want to, just bear in mind to keep to lua’s 200 local variable limit per file. (that can burn you later on, it did for me when I first got started)

However, I can say that i have a similar system and i don’t usually localize external function calls.
Some things need to be though, like say you have an external function to spawn an object, it would be best to localize that, or add them to a local table index, so you can be 100% sure you are removing them.

[import]uid: 84637 topic_id: 22840 reply_id: 91269[/import]