What happen when we build?

Hi,

Does all line of code are build or not use line remove?

Example 1:

-- Comment are they remove?

Example 2:

if false then -- we can never go in this, does it exist in the apk? end

Example 3:

value=false -- never change in all the project if value then -- is it in the apk? end

Example 4:

print("This line is in the apk?")

Example 5:

function nevercall() -- if this function is never call, does it exist in the apk? end

Example 6:

If a file in never call

   - lua file (require)

   - image (display.newImage, imageSheet…)

I realy need this information to optimize my code

Thanks

Rémi

I can’t say with certainty, but I would think of the things you listed above only comments would be removed from the compiled code.

Rob

Thank you @Rob for your answer

:frowning: on c# it’s better (a language where I know it’s exist)

With corona there is a way to apply modification to the compilator?

It may cull the code, but in my research on luac, the compiler we use, it says it only removes duplicate symbols and debugging information when used with the -O optimization command. I don’t know of any compiler that keeps comments around. As far as removing unused code, I wasn’t able to determine that from my quick search.

We don’t provide any options to control the compilation. 

Let me ask engineering if they know more.

Rob

Since Lua is a dynamic language many of the performance optimizations possible in static languages aren’t possible in Lua.  All of the code in your examples will be included in the compiler output.  Arguably some of the possible optimizations would be fine in a dynamic language (in particular, certain kinds of dead code removal) but as a matter of philosophy the Lua compiler doesn’t do any optimization.

In practice, the performance of compiled Lua is rarely an issue for Corona apps and performance improvements are more often found by changes in design than by optimizing code.

You can find information on this topic in Lua Performance Tips by Roberto Ierusalimschy (one of the fathers of Lua).

Thank you @Rob and @Perry !!!

Lua performance Tips are gold! I have alread read it a few time.

On some Lua compilator there is some algo who remove dead code like in LuaJIT.

I ask the question of dead code because on my project, with an unique code I have 2 games. I choose to don’t use Git to do it and in my code there is a lot of condition like if(it’s this game) then…

It’s realy hard to do omptimization on Corona because corona is build to be easy to use (and thank you for that), for example to blur an image, I have to display the same image in lower resolution and I can blur it with out lag. It will be realy handsome to know the weight of an instruction, not exactly the value but something to know where we have to optimize.

In my opinion, the real performance bottlenecks are in OpenGL rendering, audio mixing, Box2D physics, image/audio file loading, etc.  The Lua script byte code interpreting performance is negligible compare to those things.  Especially since your Lua script isn’t running long operations like it would for a command line utility.  Your Lua script is invoked based on events such as enterFrame, timers, physics collision, etc.

Also note that Lua is popular with AAA game studio due to its excellent performance.  For example, Blizzard uses Lua for World of Warcraft.  Lua was specifically designed to extend C/C++, making its native language binding extremely fast.

If your goal is to remove debugging functions from your code, then perhaps our system.getInfo(“environment”) function can help you out.  You can use it to identify if you’re running in the Corona Simulator or on a real device.

   https://docs.coronalabs.com/api/library/system/getInfo.html#environment

One more thing.  When you build an app, Corona will compile your Lua scripts to byte code.  We don’t interpret the raw uncompiled scripts like we do in the Corona Simulator.

Thank you @Joshua !

For the code in lua before work with corona I verify if the code was in clear or encrypt. ^^

For performance, lua code make my game lagging. Because I calculate a lot of things for the interaction between units. During the game the user can have more than 1000 units.

Thank you all for this information. If you have more information don’t hesitate to send me them! :slight_smile:

Rémi

I can’t say with certainty, but I would think of the things you listed above only comments would be removed from the compiled code.

Rob

Thank you @Rob for your answer

:frowning: on c# it’s better (a language where I know it’s exist)

With corona there is a way to apply modification to the compilator?

It may cull the code, but in my research on luac, the compiler we use, it says it only removes duplicate symbols and debugging information when used with the -O optimization command. I don’t know of any compiler that keeps comments around. As far as removing unused code, I wasn’t able to determine that from my quick search.

We don’t provide any options to control the compilation. 

Let me ask engineering if they know more.

Rob

Since Lua is a dynamic language many of the performance optimizations possible in static languages aren’t possible in Lua.  All of the code in your examples will be included in the compiler output.  Arguably some of the possible optimizations would be fine in a dynamic language (in particular, certain kinds of dead code removal) but as a matter of philosophy the Lua compiler doesn’t do any optimization.

In practice, the performance of compiled Lua is rarely an issue for Corona apps and performance improvements are more often found by changes in design than by optimizing code.

You can find information on this topic in Lua Performance Tips by Roberto Ierusalimschy (one of the fathers of Lua).

Thank you @Rob and @Perry !!!

Lua performance Tips are gold! I have alread read it a few time.

On some Lua compilator there is some algo who remove dead code like in LuaJIT.

I ask the question of dead code because on my project, with an unique code I have 2 games. I choose to don’t use Git to do it and in my code there is a lot of condition like if(it’s this game) then…

It’s realy hard to do omptimization on Corona because corona is build to be easy to use (and thank you for that), for example to blur an image, I have to display the same image in lower resolution and I can blur it with out lag. It will be realy handsome to know the weight of an instruction, not exactly the value but something to know where we have to optimize.

In my opinion, the real performance bottlenecks are in OpenGL rendering, audio mixing, Box2D physics, image/audio file loading, etc.  The Lua script byte code interpreting performance is negligible compare to those things.  Especially since your Lua script isn’t running long operations like it would for a command line utility.  Your Lua script is invoked based on events such as enterFrame, timers, physics collision, etc.

Also note that Lua is popular with AAA game studio due to its excellent performance.  For example, Blizzard uses Lua for World of Warcraft.  Lua was specifically designed to extend C/C++, making its native language binding extremely fast.

If your goal is to remove debugging functions from your code, then perhaps our system.getInfo(“environment”) function can help you out.  You can use it to identify if you’re running in the Corona Simulator or on a real device.

   https://docs.coronalabs.com/api/library/system/getInfo.html#environment

One more thing.  When you build an app, Corona will compile your Lua scripts to byte code.  We don’t interpret the raw uncompiled scripts like we do in the Corona Simulator.

Thank you @Joshua !

For the code in lua before work with corona I verify if the code was in clear or encrypt. ^^

For performance, lua code make my game lagging. Because I calculate a lot of things for the interaction between units. During the game the user can have more than 1000 units.

Thank you all for this information. If you have more information don’t hesitate to send me them! :slight_smile:

Rémi